Sha256: 82f00e72ef781facd9d798f9d481ab486b57f812a843a0b55e4d92d6bc2c7a61

Contents?: true

Size: 650 Bytes

Versions: 122

Compression:

Stored size: 650 Bytes

Contents

package triangle

import "math"

type Kind string

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

122 entries across 122 versions & 1 rubygems

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