summaryrefslogtreecommitdiffstats
path: root/tests/langbench/wc.rb
diff options
context:
space:
mode:
Diffstat (limited to 'tests/langbench/wc.rb')
-rw-r--r--tests/langbench/wc.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/langbench/wc.rb b/tests/langbench/wc.rb
new file mode 100644
index 0000000..ef19635
--- /dev/null
+++ b/tests/langbench/wc.rb
@@ -0,0 +1,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)