Skip to content

Instantly share code, notes, and snippets.

@Whatapalaver
Created May 29, 2019 15:37
Show Gist options
  • Save Whatapalaver/c751a7343f9bb758a6d6420852d795bb to your computer and use it in GitHub Desktop.
Save Whatapalaver/c751a7343f9bb758a6d6420852d795bb to your computer and use it in GitHub Desktop.
class Grains
def self.square(square_no)
raise ArgumentError, 'Square must be between 1 and 64' unless square_no >= 1 && square_no <= 64
chessboard[square_no - 1]
end
def self.chessboard
chessboard = []
(1..64).each do |square|
chessboard <<
if square == 1
1
else
chessboard[square - 2] * 2
end
end
chessboard
end
def self.total
chessboard.sum
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment