Last active
April 7, 2016 20:30
-
-
Save LordAro/f4ae43682d3e6bb4eca6a6043e21ab15 to your computer and use it in GitHub Desktop.
PE006 in Golang, at compile time.
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 main | |
//go:generate sumdiff.sh 100 | |
import "fmt" | |
func main() { | |
fmt.Println("Sum difference:", SumDiff) | |
} | |
// To run, copy sumdiff.sh to somewhere in $PATH, then run `go generate euler006.go; go run euler006.go sumdiff_100.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
#!/bin/sh | |
# Has to be in $PATH :( | |
N=$1 | |
ANS=$(echo "$N*(3*$N+2)*($N-1)*($N+1)/12" | bc) | |
cat <<EOF > sumdiff_$1.go | |
package main | |
const ( | |
SumDiff = $ANS | |
) | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment