diff options
-rw-r--r-- | 2020/two.nim | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/2020/two.nim b/2020/two.nim index 9ca94fb..a2234ab 100644 --- a/2020/two.nim +++ b/2020/two.nim @@ -1,24 +1,23 @@ import os, strutils -let input = paramStr(1) -var valid: int = 0 -var official: int = 0 +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, {'-', ' ', ':'}) - low: int = parseInt(entry[0]) - high: int = parseInt(entry[1]) + min: int = parseInt(entry[0]) + max: int = parseInt(entry[1]) letter: char = entry[2][0] - password: string = entry[4] - for char in password: + pass: string = entry[4] + for char in pass: if char == letter: inc(frequency) - if low <= frequency and frequency <= high: - inc(valid) - if password[low-1] == letter xor password[high-1] == letter: + if min <= frequency and frequency <= max: + inc(unofficial) + if pass[min-1] == letter xor pass[max-1] == letter: inc(official) -echo valid +echo unofficial echo official |