From fb2dd0f45fa8f8a1045ee9c76c1bca3cc71cb0ef Mon Sep 17 00:00:00 2001 From: j-james Date: Sun, 4 Dec 2022 23:15:53 -0800 Subject: Day Three --- 2022/nim/day03/src/main.nim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 2022/nim/day03/src/main.nim (limited to '2022/nim/day03/src') diff --git a/2022/nim/day03/src/main.nim b/2022/nim/day03/src/main.nim new file mode 100644 index 0000000..782d9f6 --- /dev/null +++ b/2022/nim/day03/src/main.nim @@ -0,0 +1,18 @@ +# Day Three: Rucksack Reorganization +import std/[os, strutils, sequtils, sugar] + +let input = paramStr(1).readFile().strip().split("\n") + +func deascii(x: char): int = + if x.ord > 96: + x.ord - 96 + else: + x.ord - 38 + +echo input.mapIt((it[0..(it.len div 2 - 1)], it[(it.len div 2)..(it.len - 1)])) + .mapIt(it[0].filter(x => x in it[1])[0]) + .mapIt(it.deascii()).foldl(a+b, 0) + +echo input.distribute(100) + .mapIt(it[0].filter(x => x in it[1] and x in it[2])[0]) + .mapIt(it.deascii()).foldl(a+b, 0) -- cgit v1.2.3-70-g09d2