aboutsummaryrefslogtreecommitdiff
path: root/challenge-026/archargelod/nim/ch_1.nim
blob: 807a9b847bda7b6f28e69c244c31be41915eec97 (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
#!/usr/bin/env -S nim r -d:release --verbosity:0 --hints:off
import std/[strutils]

proc countLetters(input, alphabet: string): int =
  let uniq = block:
    var tmp: set[char]
    for c in alphabet:
      if c notin Letters: continue
      tmp.incl c
    tmp

  for c in input:
    if c in uniq:
      inc result

when isMainModule:
  import std/unittest

  const
    Test = "chancellor"
    Alphabet = "chocolate"
    Expected = 8

  suite "Stones and jewels alphabets":
    test "Example 1":
      check Test.countLetters(Alphabet) == Expected