Skip to content

Instantly share code, notes, and snippets.

@xenda
Created September 30, 2011 01:54
Show Gist options
  • Save xenda/1252461 to your computer and use it in GitHub Desktop.
Save xenda/1252461 to your computer and use it in GitHub Desktop.
class Toss
attr_accessor :cubes
#Toss
def groups_size(n)
counts = cubes.group_by(&:face_up).map { |face, cubes| [face, cubes.size] }
counts.select { |face, count| count == n }.map(&:first)
end
end
# Module?
def groups_of_size(n)
@group ||= toss.groups_size(n).size
end
def can_score?
groups_of_size?(5)
end
def score
if groups_of_size?(5)
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment