Skip to content

Instantly share code, notes, and snippets.

@LordRahl90
Last active March 5, 2019 13:04
Show Gist options
  • Save LordRahl90/f0cda51225f282ec0d62fa1a5d41db4e to your computer and use it in GitHub Desktop.
Save LordRahl90/f0cda51225f282ec0d62fa1a5d41db4e to your computer and use it in GitHub Desktop.
Sum Square Difference project euler #6
package main
import "fmt"
func solution(limit int) int {
sum, ssq := 0, 0
for i := 1; i <= limit; i++ {
square := i * i
ssq += square
sum += i
}
sqq := sum * sum
diff := sqq - ssq
return diff
}
func main() {
limit := 100
ans := solution(limit)
fmt.Println("Answer is: ", ans)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment