aboutsummaryrefslogtreecommitdiff
path: root/challenge-252/barroff/nim/ch_1.nim
blob: d90d745333b2c96c6279aec1a5b2b21ca340a1f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import std/unittest

# run tests with following command:
# nim c -r ch_1.nim

proc special_numbers(n: openArray[int]): int =
  for i in 1 .. len(n):
    if len(n) mod i == 0:
      result += n[i - 1] * n[i - 1]

suite "special numbers":
  test "[1, 2, 3, 4]":
    check(special_numbers([1, 2, 3, 4]) == 21)

  test "[2, 7, 1, 19, 18, 3]":
    check(special_numbers([2, 7, 1, 19, 18, 3]) == 63)