Sha256: 49eb6f9ba7f8f411f055207d0a7976c967e1dccc713c1b3a5540f21033b2650f

Contents?: true

Size: 642 Bytes

Versions: 355

Compression:

Stored size: 642 Bytes

Contents

import math

type
  TriangleKind* = enum
    tkEquilateral,
    tkIsosceles,
    tkScalene

proc checkInvalidSide(f: float) =
  let fc = classify(f)
  if not (fc == fcNormal or fc == fcSubnormal) or f < 0:
    raise newException(ValueError, "invalid side: " & $f)

proc kind*(a, b, c: float): TriangleKind =
  checkInvalidSide(a)
  checkInvalidSide(b)
  checkInvalidSide(c)
  if a + b <= c or a + c <= b or b + c <= a:
    raise newException(ValueError, "one side is larger than the other two combined")
  elif a == b and b == c:
    return tkEquilateral
  elif a == b or b == c or a == c:
    return tkIsosceles
  else:
    return tkScalene

Version data entries

355 entries across 355 versions & 1 rubygems

Version Path
trackler-2.2.1.138 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.137 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.136 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.135 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.134 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.133 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.132 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.131 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.130 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.129 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.128 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.127 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.126 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.125 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.124 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.123 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.122 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.121 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.120 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.119 tracks/nim/exercises/triangle/example.nim