Skip to content

Instantly share code, notes, and snippets.

@kwoods
Last active April 21, 2016 01:31
Show Gist options
  • Save kwoods/2d19e99ec41b6d98cf26b27ca1dd6e35 to your computer and use it in GitHub Desktop.
Save kwoods/2d19e99ec41b6d98cf26b27ca1dd6e35 to your computer and use it in GitHub Desktop.
Odd = Red Ball, Even = Blue Ball
# The adding logic seems to dictate the result. So if you start with 1 ball each (differnt colors / odd),
# you end up with red.
blue_balls = Array.new(17, 'blue')
red_balls = Array.new(17, 'red')
balls = red_balls + blue_balls
balls.shuffle!
puts "Starting Ball List: #{balls}"
while balls.count > 1
take_2 = balls.shift(2)
puts "grabbing 2 balls: #{take_2}"
if take_2.uniq.count == 1 # balls are the same color
balls.push('blue') # add a blue ball back
puts "+1 blue"
elsif take_2.uniq.count == 2 # balls are differnt colors
balls.push('red') # add a red ball back
puts "+1 red"
end
end
puts "Last Ball Remaining: #{balls}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment