Skip to content

Instantly share code, notes, and snippets.

@ivoanjo
Created March 16, 2015 22:26
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 ivoanjo/bde43c2ea3ffebcd910b to your computer and use it in GitHub Desktop.
Save ivoanjo/bde43c2ea3ffebcd910b to your computer and use it in GitHub Desktop.
Ruby implementation of pairs game
#!/usr/bin/ruby
def print_number(i)
i.to_s.rjust(2, '0')
end
def validate(result)
result.each do |r1|
result.each do |r2|
next if r1 == r2
raise "Oops #{r1} & #{r2} = #{r1 & r2}" if (r1 & r2).size != 1
end
end
end
cyclic_set = [0, 1, 3, 13, 32, 36, 43, 52]
result = []
(0..56).each do |n|
result << cyclic_set.map { |m| (n + m) % 57 }
puts "#{print_number(n+1)}: #{result.last.map { |m| print_number(m+1) }.join(' ')}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment