Sha256: 5369605a82de77a6d14afdfaed45c1a406e886363ea53113e260bb5d99f360bb

Contents?: true

Size: 673 Bytes

Versions: 274

Compression:

Stored size: 673 Bytes

Contents

package triangle

import "math"

type Kind string

const testVersion = 3

const (
	Equ Kind = "equilateral"
	Iso      = "isosceles"
	Sca      = "scalene"
	NaT      = "not a triangle"
)

func KindFromSides(a, b, c float64) Kind {
	if math.IsNaN(a) || math.IsNaN(b) || math.IsNaN(c) {
		return NaT
	}
	if a > b {
		a, b = b, a
	}
	if b > c {
		b, c = c, b
	}
	if a > b {
		a, b = b, a
	}
	// sides are now sorted
	switch {
	case math.IsInf(c, 1): // largest side is +Inf, guards against (3, +Inf, +Inf)
		return NaT
	case a <= 0:
		return NaT
	case a+b < c: // triangle inequality
		return NaT
	case a == c:
		return Equ
	case a == b || b == c:
		return Iso
	}
	return Sca
}

Version data entries

274 entries across 274 versions & 1 rubygems

Version Path
trackler-2.1.0.39 tracks/go/exercises/triangle/example.go
trackler-2.1.0.38 tracks/go/exercises/triangle/example.go
trackler-2.1.0.37 tracks/go/exercises/triangle/example.go
trackler-2.1.0.36 tracks/go/exercises/triangle/example.go
trackler-2.1.0.34 tracks/go/exercises/triangle/example.go
trackler-2.1.0.33 tracks/go/exercises/triangle/example.go
trackler-2.1.0.32 tracks/go/exercises/triangle/example.go
trackler-2.1.0.31 tracks/go/exercises/triangle/example.go
trackler-2.1.0.30 tracks/go/exercises/triangle/example.go
trackler-2.1.0.29 tracks/go/exercises/triangle/example.go
trackler-2.1.0.28 tracks/go/exercises/triangle/example.go
trackler-2.1.0.27 tracks/go/exercises/triangle/example.go
trackler-2.1.0.26 tracks/go/exercises/triangle/example.go
trackler-2.1.0.25 tracks/go/exercises/triangle/example.go
trackler-2.1.0.24 tracks/go/exercises/triangle/example.go
trackler-2.1.0.23 tracks/go/exercises/triangle/example.go
trackler-2.1.0.22 tracks/go/exercises/triangle/example.go
trackler-2.1.0.21 tracks/go/exercises/triangle/example.go
trackler-2.1.0.20 tracks/go/exercises/triangle/example.go
trackler-2.1.0.19 tracks/go/exercises/triangle/example.go