SMEUV6K6UNHLMOVUIX7TEC5PXFADQG3TA5GQH45J5JEOEE3V44QAC
// Package grains if for counting grains on the chess board.
package grains
import (
"fmt"
)
// Square returns the number of grains on n-th square. Error in case of n<1 and n>64.
func Square(n int) (uint64, error) {
if n < 1 || n > 64 {
return 0, fmt.Errorf("input must be positive and <= 64, got: %q", n)
}
return 1 << (n - 1), nil
}
// Total returns all the grains on a chessboard.
func Total() uint64 {
var sum uint64
for i := 1; i < 65; i++ {
tmp, err := Square(i)
if err != nil {
return 0
}
sum += tmp
}
return sum
}