From 7f136de3efe6f4a6637526cf141b5bef84d18408 Mon Sep 17 00:00:00 2001 From: kplaczek Date: Wed, 22 Dec 2021 20:20:44 +0100 Subject: [PATCH] Day 21 and 22 part1 in both of them works part2 is something quite different. --- 21/input | 2 + 21/input.sample | 0 21/part1.php | 37 +++++ 21/part2.php | 3 + 22/input | 420 ++++++++++++++++++++++++++++++++++++++++++++++++ 22/input.sample | 20 +++ 22/part1.php | 18 +++ 22/part2.php | 3 + 8 files changed, 503 insertions(+) create mode 100644 21/input create mode 100644 21/input.sample create mode 100644 21/part1.php create mode 100644 21/part2.php create mode 100644 22/input create mode 100644 22/input.sample create mode 100644 22/part1.php create mode 100644 22/part2.php diff --git a/21/input b/21/input new file mode 100644 index 0000000..6bb2e69 --- /dev/null +++ b/21/input @@ -0,0 +1,2 @@ +Player 1 starting position: 6 +Player 2 starting position: 4 diff --git a/21/input.sample b/21/input.sample new file mode 100644 index 0000000..e69de29 diff --git a/21/part1.php b/21/part1.php new file mode 100644 index 0000000..9f01ca6 --- /dev/null +++ b/21/part1.php @@ -0,0 +1,37 @@ + 6, 'score' => 0]; +$playerB = ['position' => 4, 'score' => 0]; +$totalDiceRolls = 0; +while (max([$playerA['score'], $playerB['score']]) < 1000) { + $rolls = 0; + + $rolls += ++$totalDiceRolls; + $rolls += ++$totalDiceRolls; + $rolls += ++$totalDiceRolls; + + $playerScore = ($playerA['position'] + $rolls) % 10; + if (($playerA['position'] + $rolls) % 10 === 0) { + $playerScore = 10; + } + $playerA['position'] = $playerScore; + $playerA['score'] += $playerScore; + + if ($playerA['score'] >= 1000) { + break; + } + $rolls = 0; + + $rolls += ++$totalDiceRolls; + $rolls += ++$totalDiceRolls; + $rolls += ++$totalDiceRolls; + + $playerScore = ($playerB['position'] + $rolls) % 10; + if (($playerB['position'] + $rolls) % 10 === 0) { + $playerScore = 10; + } + $playerB['position'] = $playerScore; + $playerB['score'] += $playerScore; + +} +echo min([$playerA['score'], $playerB['score']]) * $totalDiceRolls; //920580 diff --git a/21/part2.php b/21/part2.php new file mode 100644 index 0000000..d1099fb --- /dev/null +++ b/21/part2.php @@ -0,0 +1,3 @@ +on|off) x=(-?\d*)..(-?\d*),y=(-?\d*)..(-?\d*),z=(-?\d*)..(-?\d*)#', $line, $found); + for ($x = (int)$found[2]; $x <= (int)$found[3]; $x++) { + for ($y = (int)$found[4]; $y <= (int)$found[5]; $y++) { + for ($z = (int)$found[6]; $z <= (int)$found[7]; $z++) { + unset($array[$x . '|' . $y . '|' . $z]); + if ($found['status'] == 'on') { + $array[$x . '|' . $y . '|' . $z] = 1; + } + } + } + } +} +echo count($array); //644257 \ No newline at end of file diff --git a/22/part2.php b/22/part2.php new file mode 100644 index 0000000..d1099fb --- /dev/null +++ b/22/part2.php @@ -0,0 +1,3 @@ +