aboutsummaryrefslogtreecommitdiff
path: root/2020
diff options
context:
space:
mode:
authorj-james2020-12-03 06:29:55 +0000
committerj-james2020-12-03 06:29:55 +0000
commit7ffad964f3fab79b29f5705d1481a93613921a66 (patch)
tree2d56b30c962a62bca1a87df132f76c1ce4491d99 /2020
parent6be98e592ee02eed7e15678982183164fe61c5c9 (diff)
Day Two: Clean up code
Diffstat (limited to '2020')
-rw-r--r--2020/two.nim21
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