Sha256: d683d5e2847af5d24aefb7ef125a0b9f55cec0ecf14e9be1a6107089a9ab82c1

Contents?: true

Size: 533 Bytes

Versions: 238

Compression:

Stored size: 533 Bytes

Contents

package pythagorean

type Triplet [3]int

func pyth(a, b, c int) bool {
	return a*a+b*b == c*c
}

func Range(min, max int) (ts []Triplet) {
	for a := min; a <= max; a++ {
		for b := a; b <= max; b++ {
			for c := b; c <= max; c++ {
				if pyth(a, b, c) {
					ts = append(ts, Triplet{a, b, c})
				}
			}
		}
	}
	return
}

func Sum(sum int) (ts []Triplet) {
	max := sum / 2
	for a := 1; a <= max; a++ {
		for b := a; b <= max; b++ {
			if c := sum - a - b; pyth(a, b, c) {
				ts = append(ts, Triplet{a, b, c})
			}
		}
	}
	return
}

Version data entries

238 entries across 238 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.179 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.178 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.177 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.176 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.175 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.174 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.173 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.172 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.171 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.170 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.169 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.167 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.166 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.165 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.164 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.163 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.162 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.161 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.160 tracks/go/exercises/pythagorean-triplet/example.go