Created
August 18, 2019 06:51
-
-
Save subeshb1/408aebe1d811b0ead3a5432873d663b7 to your computer and use it in GitHub Desktop.
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
// CH002 :: Pythagorean Triplet | |
package main | |
import "fmt" | |
func pythagoreanTriplet(number int) (int, int, int) { | |
for first := 1; first <= number/2; first++ { | |
for second := first + 1; second <= number/2; second++ { | |
third := number - (first + second) | |
if (first*first)+(second*second) == (third * third) { | |
return first, second, third | |
} | |
} | |
} | |
return 0, 0, 0 | |
} | |
func main() { | |
fmt.Println(pythagoreanTriplet(1000)) // 200 375 425 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment