summaryrefslogtreecommitdiffstats
path: root/tests/langbench/wc.rb
blob: ef1963534b9961e4f39d84956a4fac602e351df2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def wordsplit(line)
    list = []
    word = ""
    line.split('').each do |c|
	if c =~ /\s/
	    if word.length > 0
		list << word
	    end
	    word = ""
	else
	    word += c
	end
    end
    if word.length > 0
	list << word
    end
    return list
end

n = 0
while line = gets()
    words = wordsplit(line)
    n += words.length
end
printf("%d\n", n)