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.139 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.138 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.137 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.136 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.135 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.134 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.133 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.132 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.131 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.130 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.129 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.128 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.127 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.126 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.125 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.124 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.123 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.122 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.121 tracks/go/exercises/pythagorean-triplet/example.go
trackler-2.2.1.120 tracks/go/exercises/pythagorean-triplet/example.go