Skip to content

Instantly share code, notes, and snippets.

View neill's full-sized avatar

Neill N Silva III neill

View GitHub Profile
@neill
neill / ball_weight.rb
Created February 3, 2015 21:22
If 7 balls, determine which is lightest in the least amount of weighs.
ball1, ball2, ball3, ball4, ball5, ball6, ball7 = 2.7, 2.5, 2.7, 2.7, 2.7, 2.7, 2.7
group1 = [ball1, ball2, ball3]
group2 = [ball4, ball5, ball6]
if group1.inject(:+) == group2.inject(:+)
puts "Ball 7 is the lightest."
elsif group1.inject(:+) < group2.inject(:+)
case group1[0] <=> group1[1]
when 0
puts "Ball 3 is the lightest."