aboutsummaryrefslogtreecommitdiff
path: root/2020/two.nim
blob: a2234ab867c7cfbad690ecb43ded8072fec756eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os, strutils

let input: string = paramStr(1)
var unofficial, official: int = 0

for line in lines(input):
  var frequency: int = 0
  let
    entry: seq[string] = split(line, {'-', ' ', ':'})
    min: int = parseInt(entry[0])
    max: int = parseInt(entry[1])
    letter: char = entry[2][0]
    pass: string = entry[4]
  for char in pass:
    if char == letter:
      inc(frequency)
  if min <= frequency and frequency <= max:
    inc(unofficial)
  if pass[min-1] == letter xor pass[max-1] == letter:
    inc(official)

echo unofficial
echo official