Skip to content

Instantly share code, notes, and snippets.

@subeshb1
Created August 18, 2019 06:51
Show Gist options
  • Save subeshb1/408aebe1d811b0ead3a5432873d663b7 to your computer and use it in GitHub Desktop.
Save subeshb1/408aebe1d811b0ead3a5432873d663b7 to your computer and use it in GitHub Desktop.
// 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