aboutsummaryrefslogtreecommitdiff
path: root/2020/two.nim
blob: 74bb1708a894f577eb37db08085adabc726ae81a (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
24
# Day Two: Password Philosophy
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