Skip to content

Commit 015e2b4

Browse files
author
Rafal Gajdulewicz
committed
Solved 9
1 parent 4cbe9c3 commit 015e2b4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

9.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"math"
6+
)
7+
8+
func main() {
9+
for a := 1; a < 1000; a++ {
10+
for b := a; b < 1000-a; b++ {
11+
hass, c := hasSqrt(a*a + b*b)
12+
if hass && a+b+c == 1000 {
13+
fmt.Printf("%d^2 + %d^2 = %d^2\n", a*a, b*b, c*c)
14+
fmt.Printf("%d + %d + %d = 1000\n", a, b, c)
15+
16+
}
17+
}
18+
}
19+
}
20+
21+
func hasSqrt(n int) (bool, int) {
22+
sq := math.Sqrt(float64(n))
23+
return float64(int(sq)) == sq, int(sq)
24+
}

0 commit comments

Comments
 (0)