From 7be570c4a6e86fb7060f0bc06910ca57003dfe90 Mon Sep 17 00:00:00 2001 From: Orfeas <38209077+0xfea5@users.noreply.github.com> Date: Sat, 8 Jun 2024 13:50:47 +0300 Subject: Update file names and init.sh --- day3/solution.nim | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 day3/solution.nim (limited to 'day3/solution.nim') diff --git a/day3/solution.nim b/day3/solution.nim deleted file mode 100644 index 6df88f2..0000000 --- a/day3/solution.nim +++ /dev/null @@ -1,47 +0,0 @@ -import std/strutils -import std/sequtils -import std/sets - -proc Points(c: char): int = - if c.isLowerAscii(): - return ord(c) - ord('a') + 1 - else: - return ord(c) - ord('A') + 27 - -proc part1(content: seq[string]): int = - let ruckshacks = map( content, - proc(line: string): tuple[first: string, second: string] = - let pivot = int(line.len()/2) - (line[0 .. pivot-1], line[pivot .. ^1]) - ) - - var score = 0 - for ruckshack in ruckshacks: - let - uniqFirst = toHashSet(ruckshack.first) - uniqSecond = toHashSet(ruckshack.second) - - var c = toSeq(uniqFirst * uniqSecond)[0] - score += Points(c) - - return score - -proc part2(content: seq[string]): int = - assert(content.len() mod 3 == 0) - - let ruckshacks = content - var score = 0 - for i in countup(0, ruckshacks.len()-1, 3): - let - uniqFirst = toHashSet(ruckshacks[i]) - uniqSecond = toHashSet(ruckshacks[i+1]) - uniqThird = toHashSet(ruckshacks[i+2]) - - var c = toSeq(uniqFirst * uniqSecond * uniqThird)[0] - score += Points(c) - - return score - -let content = readFile("./input.txt").strip().split("\n") -echo part1(content) -echo part2(content) -- cgit v1.2.3