There are 64 squares on a chessboard. Every square has the double that the one before. Write a program that shows: - how many grains were on each square, and - the total number of grains
My code is working for the first part, but I have problems declaring the total. Some basic class/method declaration that I am missing. Thanks for helping.
class Grains
def square(n)
array_of_grains = []
(0..63).each {|x| array_of_grains << 2**x}
n = n-1
array_of_grains[n]
end
def total
array_of_grains.each {|x| sum += x }
end
end