Skip to content

Instantly share code, notes, and snippets.

@LordAro
Last active April 7, 2016 20:30
Show Gist options
  • Save LordAro/f4ae43682d3e6bb4eca6a6043e21ab15 to your computer and use it in GitHub Desktop.
Save LordAro/f4ae43682d3e6bb4eca6a6043e21ab15 to your computer and use it in GitHub Desktop.
PE006 in Golang, at compile time.
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`
#!/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