Created
June 14, 2021 13:16
-
-
Save prune998/3ec2c1ff3cbe8b63b98abee8e4dc17a7 to your computer and use it in GitHub Desktop.
grains.go
This file contains 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
package grains | |
import "errors" | |
func Square(i int) (uint64, error) { | |
// fail fast | |
if i < 1 || i > 64 { | |
return 0, errors.New("square is out of range") | |
} | |
// use binay shift | |
var result uint64 = 1 << (i - 1) | |
return result, nil | |
} | |
func Total() uint64 { | |
// Total is equal to 65 squares -1 | |
result, _ := Square(65) | |
return result - 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment