Skip to content

Instantly share code, notes, and snippets.

@bergmark
Created January 17, 2012 07:34
Show Gist options
  • Select an option

  • Save bergmark/1625460 to your computer and use it in GitHub Desktop.

Select an option

Save bergmark/1625460 to your computer and use it in GitHub Desktop.
fallout hack solver
#!/usr/bin/env ruby
pairs = []
while !(print '> ') && (s = gets.strip) != ''
word,num = /^(\S+)\s*(\d+)?$/.match(s)[1..2]
if num
pairs << [word,num.to_i]
else
print(pairs.map { |p_word,p_num|
p_num == word.chars.zip(p_word.chars).inject(0) { |s,(a,b)| s + (a == b ? 1 : 0) }
}.all? ? "match\n" : "no match\n")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment