Files
advent_of_code_2025/day_1/part_1.php
2025-12-10 15:01:52 +01:00

35 lines
848 B
PHP

<?php
$lines = array_filter(explode("\n", file_get_contents(__DIR__.'/input.txt')), static fn($line) =>!empty($line));
$count = 0;
$position = 50;
echo 'The dial starts by pointing at 50'."\n";
function checkPosition(&$position)
{
if ($position < 0) {
$position = 100 - abs($position);
} elseif ($position > 99) {
$position = $position - 100;
}
}
foreach ($lines as $line) {
$direction = substr($line, 0, 1);
$number = (int)substr($line, 1) % 100;
if ($direction === 'L') {
$position -= $number;
checkPosition($position);
} elseif ($direction === 'R') {
$position += $number;
checkPosition($position);
}
if ($position === 0) {
$count++;
}
echo sprintf('The dial is rotated %s to point at %u | count : %u%s', $line,$position, $count, "\n");
}