Created
May 20, 2019 20:27
-
-
Save pauladams8/e6a91c992b0c331b7e89c049ef7d8e38 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
"os" | |
) | |
func isTriplet(a int, b int, c int) bool { | |
if (a * a + b * b == c * c) { | |
return true | |
} | |
return false | |
} | |
func getProduct (a int, b int, c int) int { | |
return a * b * c | |
} | |
func main() { | |
fmt.Println("Finding product of Pythagorean triplet that sums to 1000...\n") | |
var aim int = 1000 | |
for a := 1; a <= aim / 3; a++ { | |
for b := a + 1; b <= aim / 2; b++ { | |
var c int = aim - a - b | |
if isTriplet(a, b ,c) { | |
product := getProduct(a, b, c) | |
fmt.Println("Found!") | |
fmt.Println(product) | |
fmt.Println("\nFYI the numbers were") | |
for _, number := range [3]int{a, b, c} { | |
fmt.Println(number) | |
} | |
os.Exit(3) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment