Skip to content

Instantly share code, notes, and snippets.

/asdf.cr Secret

Created May 20, 2017 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/cd9122225f5511def01a3351976232f3 to your computer and use it in GitHub Desktop.
Save anonymous/cd9122225f5511def01a3351976232f3 to your computer and use it in GitHub Desktop.
class Asdf
@@old_spots = [false] * 100
@@words = File.read("/usr/share/dict/words").split("\n").map(&.downcase)
sym_arr = File.read("syms.txt").split("\n").map(&.downcase).map{|sym| sym.split("")}
@@symbols = uninitialized Set[String]
@@symbols = Set.new(sym_arr)
def works(word, offset)
if offset == word.size
return true
end
res = false
@@spots[offset] = true
if !@@spots[offset + 1] && symbols.contains([word[offset]])
res ||= works(word, offset + 1)
end
if !@@spots[offset + 2] && symbols.contains([word[offset], word[offset + 1]])
res ||= works(word, offset + 2)
end
return res
end
def run()
words.select do |word|
@@spots = @@old_spots.clone
works(word, 0)
end.sort.reverse
end
end
Asdf.new().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment