Created
May 29, 2019 15:37
-
-
Save Whatapalaver/c751a7343f9bb758a6d6420852d795bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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