Skip to content

Commit

Permalink
Day 11 Part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Marshall Davis committed Dec 11, 2024
1 parent 5fde511 commit 06adfd3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 2024/11/puzzle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

$inputStream = fopen('input.txt', 'r+');
$stones = explode(' ', trim(fgets($inputStream)));
echo implode(' ', $stones).PHP_EOL;
$blinks = 25;
for ($blink = 1; $blink <= $blinks; $blink++) {
$transformed = [];
$splits = 0;
foreach ($stones as $position => $engraving) {
if ($engraving === '0') {
$transformed[$position + $splits] = 1;
} elseif (($length = strlen($engraving)) % 2 === 0) {
$first = substr($engraving, 0, $length / 2);
$second = substr($engraving, ($length / 2));
array_splice($transformed, $position + $splits, 1, [(string) (int) $first, (string) (int) $second]);
++$splits;
} else {
$transformed[$position + $splits] = $engraving * 2024;
}
}
$stones = $transformed;
echo "Blink $blink: ".count($stones).PHP_EOL;
// echo implode(' ', $stones).PHP_EOL.PHP_EOL;
}

echo "FINAL: ".count($stones).PHP_EOL;

0 comments on commit 06adfd3

Please sign in to comment.