aboutsummaryrefslogtreecommitdiff
path: root/challenge-041/archargelod/nim/ch_2.nim
blob: 8777e9cd305bf0662b559ac857e748b7a2af6d93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env -S nim r -d:release --verbosity:0 --hints:off

proc leonardoNumbers(n: int): seq[int] =
  result = newSeq[int](n)
  result[0..1] = [1, 1]
  for i in 2..<n:
    result[i] = result[i-2] + result[i-1] + 1

when isMainModule:
  import std/unittest

  const
    Expected = [
      1, 1, 3, 5, 9, 15, 25, 41, 67, 109, 177, 287, 465, 753, 1219, 1973, 3193,
      5167, 8361, 13529
    ]

  suite "Leonardo numbers":
    test "first 20":
      check leonardoNumbers(20) == Expected