From 24520cb3b6eae75e9c755b324cc892e02c1a54dd Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Sat, 3 Dec 2022 19:26:02 +1030 Subject: [PATCH] 2022 Day 3 Nim (not good) --- 2022/day3.nim | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 2022/day3.nim diff --git a/2022/day3.nim b/2022/day3.nim new file mode 100644 index 0000000..0a0b31c --- /dev/null +++ b/2022/day3.nim @@ -0,0 +1,35 @@ +{.hint[name]: off.} # snake_case > camelCase +import sequtils +import strutils +import std/sets +import sugar + +let elves = split_lines strip read_file "input/3" + +proc get_priority(c: char): int = + if c in 'a'..'z': + return ord(c) - ord('a') + 1 + return ord(c) - ord('A') + 27 + +# Part 1 +proc part_1_score(line: string): int = + let halflen = len(line) shr 1 + var knapsack_1 = collect initHashSet: # Couldn't work out how to collect to set[char] + for c in line[0..