From f45a13c6a1438e38728d74cbdec53692c48a9412 Mon Sep 17 00:00:00 2001 From: Tatu Pesonen Date: Wed, 4 Dec 2024 18:17:24 +0200 Subject: [PATCH] feat(day3): day 3 in PHP --- aoc2024/src/days/day3_part1.php | 57 +++++++++++++++++++++ aoc2024/src/days/day3_part2.php | 87 +++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 aoc2024/src/days/day3_part1.php create mode 100644 aoc2024/src/days/day3_part2.php diff --git a/aoc2024/src/days/day3_part1.php b/aoc2024/src/days/day3_part1.php new file mode 100644 index 0000000..6af92df --- /dev/null +++ b/aoc2024/src/days/day3_part1.php @@ -0,0 +1,57 @@ + 7) { + } else { + $nums[] = substr($input, $i, $next); + } + } + else { + echo "No match for " . $arr[$i] . "\n"; + $validParsed = 0; + } +} + +$muls = []; +foreach($nums as $mul) { + $x = explode(",", $mul); + $muls[] = $x; +} + +$total = 0; +foreach($muls as $mul) { + $total += (int)$mul[0] * (int)$mul[1]; +} + +var_dump($total); + + + + diff --git a/aoc2024/src/days/day3_part2.php b/aoc2024/src/days/day3_part2.php new file mode 100644 index 0000000..5669a8f --- /dev/null +++ b/aoc2024/src/days/day3_part2.php @@ -0,0 +1,87 @@ + 7) { + } else { + $nums[] = substr($input, $i, $next); + } + } + else { + echo "No match for mul " . $arr[$i] . "\n"; + $validParsedMul = 0; + } + } +} + +$muls = []; +foreach($nums as $mul) { + $x = explode(",", $mul); + $muls[] = $x; +} + +$total = 0; +foreach($muls as $mul) { + $total += (int)$mul[0] * (int)$mul[1]; +} + +var_dump($total); + + + +