Sha256: 1b5e7fb25bfc67bc82c9856d781353fc7bf6691d9085fec6e3887da2345fa507

Contents?: true

Size: 742 Bytes

Versions: 21

Compression:

Stored size: 742 Bytes

Contents

import sequtils

proc valid(a, b, c: int): bool =
    let greatThenZero = all([a, b, c], proc (x: int): bool = return x > 0)
    let equalityCheck = (a + b >= c) and (a + c >= b) and (b + c >= a)

    greatThenZero and equalityCheck

proc is_equilateral*(sides: array[3, int]): bool =
    let a = sides[0]
    let b = sides[1]
    let c = sides[2]
    valid(a, b, c) and all(sides, proc (x: int): bool = return a == x)

proc is_isosceles*(sides: array[3, int]): bool =
    let a = sides[0]
    let b = sides[1]
    let c = sides[2]
    valid(a, b, c) and (a == b or b == c or a == c)

proc is_scalene*(sides: array[3, int]): bool =
    let a = sides[0]
    let b = sides[1]
    let c = sides[2]
    valid(a, b, c) and not is_isosceles(sides)

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.158 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.157 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.156 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.155 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.154 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.153 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.152 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.151 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.150 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.149 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.148 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.147 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.146 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.145 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.144 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.143 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.142 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.141 tracks/nim/exercises/triangle/example.nim
trackler-2.2.1.140 tracks/nim/exercises/triangle/example.nim