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.77 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.76 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.75 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.74 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.73 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.72 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.71 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.70 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.69 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.68 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.67 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.66 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.65 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.64 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.63 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.62 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.61 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.60 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.59 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.58 tracks/nim/exercises/triangle/example.nim