diff --git a/Makefile b/Makefile index 8703c1e..3bc71c2 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,8 @@ day4: php day4/main.php day5: + php day5/main.php + day6: day7: day8: diff --git a/day5/main.php b/day5/main.php new file mode 100644 index 0000000..d36c8c4 --- /dev/null +++ b/day5/main.php @@ -0,0 +1,52 @@ += count($instructions)) { + return $jumps; + } + } +} + +function puzzle2(string $input) +{ + $jumps = 0; + $placement = 0; + $instructions = array_filter(explode(PHP_EOL, $input)); + + while (true) { + // Get current jump size + $jumpSize = $instructions[$placement]; + + // Update instructions + if ($instructions[$placement] >= 3) { + $instructions[$placement]--; + } else { + $instructions[$placement]++; + } + + // Do jump + $placement += $jumpSize; + $jumps++; + + if ($placement >= count($instructions)) { + return $jumps; + } + } +}