Last active
March 5, 2019 13:04
-
-
Save LordRahl90/f0cda51225f282ec0d62fa1a5d41db4e to your computer and use it in GitHub Desktop.
Sum Square Difference project euler #6
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 | |
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