Commit cfa4cc9
build.sh
@@ -1,3 +1,3 @@
#!/bin/sh
-
+./level0
# Add any build steps you need here
level0
@@ -1,25 +1,28 @@
-#!/usr/bin/env ruby
+#!/usr/bin/python
+import sys
+import re
-# Our test cases will always use the same dictionary file (with SHA1
-# 6b898d7c48630be05b72b3ae07c5be6617f90d8e). Running `test/harness`
-# will automatically download this dictionary for you if you don't
-# have it already.
+if len(sys.argv)>1: path=sys.argv[1]
+else: path="/usr/share/dict/words"
+entries = set([line.strip() for line in open(path)])
-class Array
- def faster_include?(n)
- !(self & [n]).empty?
- end
-end
+def words(f):
+ for i,l in enumerate(f):
+ for w in l.split():
+ yield w
+ yield " "
+ yield "\n"
-path = ARGV.length > 0 ? ARGV[0] : '/usr/share/dict/words'
-entries = File.read(path).split("\n")
+wordgen = words(sys.stdin)
-contents = $stdin.read
-output = contents.gsub(/[^ \n]+/) do |word|
- if entries.faster_include?(word.downcase)
- word
- else
- "<#{word}>"
- end
-end
+output = ''
+for word in wordgen:
+ if word.lower() in entries:
+ output+=word
+ elif (word == "\n"):
+ output+="\n"
+ elif (word == " "):
+ output+=" "
+ else:
+ output+="<"+word+">"
print output
level0.rb
@@ -0,0 +1,25 @@
+#!/usr/bin/env ruby
+
+# Our test cases will always use the same dictionary file (with SHA1
+# 6b898d7c48630be05b72b3ae07c5be6617f90d8e). Running `test/harness`
+# will automatically download this dictionary for you if you don't
+# have it already.
+
+class Array
+ def faster_include?(n)
+ !(self & [n]).empty?
+ end
+end
+
+path = ARGV.length > 0 ? ARGV[0] : '/usr/share/dict/words'
+entries = File.read(path).split("\n")
+
+contents = $stdin.read
+output = contents.gsub(/[^ \n]+/) do |word|
+ if entries.faster_include?(word.downcase)
+ word
+ else
+ "<#{word}>"
+ end
+end
+print output