#!/usr/bin/env php $item === '(' ? 1 : -1, $input); echo "Part 1: final floor:"; echo array_reduce($actions, fn (int $a, int $b): int => $a + $b, 0) . "\n"; function find_sum_index(array $actions, int $target = -1): int { $current = 0; foreach ($actions as $idx => $val) { $current += $val; if ($current === $target) { return $idx + 1; } } } echo "Part 2: first step in basement:"; echo find_sum_index($actions, -1) . "\n";