aboutsummaryrefslogtreecommitdiff
path: root/challenge-255/barroff/nim/ch_1.nim
blob: 3fb1882ca73f2f1baed559231bea865f642eb40f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import std/[sugar, unittest]

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

proc odd_character(s, t: string): char =
  let
    s_split = collect:
      for c in s: c
    t_split = collect:
      for c in t: c

  for i in 0..<len(s):
    if s_split[i] != t_split[i]:
      return t_split[i]
  return t_split[^1]

suite "odd character":
  test "Perl":
    check(odd_character("Perl", "Peerl") == 'e')

  test "Weekly":
    check(odd_character("Weekly", "Weeakly") == 'a')

  test "Box":
    check(odd_character("Box", "Boxy") == 'y')