Created
March 16, 2015 22:26
-
-
Save ivoanjo/bde43c2ea3ffebcd910b to your computer and use it in GitHub Desktop.
Ruby implementation of pairs game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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