Starting on day21 part 2

This commit is contained in:
Daniel Flanagan 2021-12-21 12:43:10 -06:00
parent b93905b565
commit 9ba9242e3c
Signed by: lytedev
GPG Key ID: 5B2020A0F9921EF4
2 changed files with 33 additions and 3 deletions

View File

@ -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)

32
2021/nim/day21.nim Normal file
View File

@ -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)