From 9ba9242e3c1fe4d9f46b0cedc4d71ec42ad9ebf7 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Tue, 21 Dec 2021 12:43:10 -0600 Subject: [PATCH] Starting on day21 part 2 --- 2021/nim/day20.nim | 4 +--- 2021/nim/day21.nim | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 2021/nim/day21.nim diff --git a/2021/nim/day20.nim b/2021/nim/day20.nim index 79b72fa..3206494 100644 --- a/2021/nim/day20.nim +++ b/2021/nim/day20.nim @@ -63,7 +63,6 @@ proc solver(input: Lines, times: int): uint64 = if v: inc result proc p1(input: Lines): uint64 = input.solver(2) - proc p2(input: Lines): uint64 = input.solver(50) const input = """ @@ -73,6 +72,5 @@ const input = """ #.... ##..# ..#.. -..### -""".strip().split('\n') +..### """.strip().split('\n') doDayX 20, (n: int) => n.loadInput, p1, p2, (input, 35'u64, 3351'u64) diff --git a/2021/nim/day21.nim b/2021/nim/day21.nim new file mode 100644 index 0000000..6886fe8 --- /dev/null +++ b/2021/nim/day21.nim @@ -0,0 +1,32 @@ +import ./common, std/[sequtils, algorithm, sugar, sets, strformat, strutils, tables, options, json, hashes, random] + +proc p1(input: Lines): uint64 = + const DIE_FACES = 100 + const TARGET_SCORE = 1000 + const BOARD_POSITIONS = 10 + + var scores = [0, 0] + var pos = [input[0].split(": ")[1].parseInt - 1, input[1].split(": ")[1].parseInt - 1] + var rollNum = 1 + var turn = 0 + while scores[0] < TARGET_SCORE and scores[1] < TARGET_SCORE: + var move = 0 + for _ in 1..3: + move += rollNum mod DIE_FACES + inc rollNum + pos[turn] = (pos[turn] + move) mod BOARD_POSITIONS + scores[turn] += pos[turn] + 1 + echo &"{move}, {pos[turn]}, {scores}" + turn = (turn + 1) mod 2 + + echo rollNum, scores + uint64(scores[turn mod 2] * (rollNum - 1)) + +proc p2(input: Lines): uint64 = + 0 + +const input = """ +Player 1 starting position: 4 +Player 2 starting position: 8 +""".strip().split('\n') +doDayX 21, (n: int) => n.loadInput, p1, p2, (input, 739785'u64, 444356092776315'u64)