Day 21 and 22 part1 in both of them works part2 is something quite different.

This commit is contained in:
kplaczek
2021-12-22 20:20:44 +01:00
parent 8acd426a62
commit 7f136de3ef
8 changed files with 503 additions and 0 deletions

2
21/input Normal file
View File

@@ -0,0 +1,2 @@
Player 1 starting position: 6
Player 2 starting position: 4

0
21/input.sample Normal file
View File

37
21/part1.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
$playerA = ['position' => 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

3
21/part2.php Normal file
View File

@@ -0,0 +1,3 @@
<?php
$input = file('input', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);