DEV Community

Discussion on: Daily Challenge #134 - Rice and Chessboard Problem

Collapse
 
hyftar profile image
Simon Landry

Ruby:

def squaresNeeded(grain)
  return 0 if grain.zero?
  square = 0
  sum = 0
  loop do
    sum += 2 ** square
    square += 1
    break if sum >= grain
  end

  square
end