Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

chating is bad mkay?

  • Loading branch information...
commit 71325d80135316615c49722eaece2d81ae893033 0 parents
@tobi authored
Showing with 49 additions and 0 deletions.
  1. +19 −0 narrow.rb
  2. +30 −0 solve.rb
19 narrow.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+#
+# Find words containing all the latters passed in
+#
+# cat /usr/share/dict/words | ./solve.rb ayfdinzhscmggnziexbeopnai | ./narrow.rb abc
+#
+
+letters = ARGV[0].chars.to_a
+
+STDIN.each_line do |line|
+ word = line.to_s.strip.downcase
+ left = letters.dup
+
+ word.chars.each do |c|
+ left.delete(c)
+ end
+
+ puts word if left.empty?
+end
30 solve.rb
@@ -0,0 +1,30 @@
+#!/usr/bin/env ruby
+#
+# Find dictionary of words contained in a game of letterpress
+#
+# reads lines from standard in and returns
+# the lines that match all passed in characters
+#
+# cat /usr/share/dict/words | ./solve.rb ayfdinzhscmggnziexbeopnai
+#
+
+letters = ARGV[0].chars.to_a
+matches = []
+
+STDIN.each_line do |line|
+ word = line.to_s.strip.downcase
+ left = letters.dup
+
+ ok = true
+
+
+ found = word.chars.each do |c|
+ if left.delete(c) == nil
+ break false
+ end
+ end
+
+ matches.push(word) if found
+end
+
+matches.sort { |a,b| b.length <=> a.length }.each { |word| puts word }
Please sign in to comment.
Something went wrong with that request. Please try again.