Skip to content

Instantly share code, notes, and snippets.

@mscha
Last active December 3, 2025 11:52
Show Gist options
  • Select an option

  • Save mscha/cd7c176a573144689c20f7f091d0fe75 to your computer and use it in GitHub Desktop.

Select an option

Save mscha/cd7c176a573144689c20f7f091d0fe75 to your computer and use it in GitHub Desktop.
Advent of Code 2025 day 3
#!/usr/bin/env raku
use v6.d;
$*OUT.out-buffer = False; # Autoflush
# Advent of Code 2025 day 3 -- https://adventofcode.com/2025/day/3
unit sub MAIN(IO() $inputfile where *.f = 'aoc03.input', Bool :v($verbose) = False);
sub joltage($bank, $count=2)
{
# Find the first occurrence of the highest digit in the bank
# (excluding the final count-1 ones)
my $digit1 = $bank.substr(0, *-($count-1)).comb.max;
my $pos1 = $bank.index($digit1);
# If there are more batteries to switch on, do so recursively
my $joltage = $count > 1 ?? $digit1 ~ joltage($bank.substr($pos1+1), $count-1)
!! $digit1;
say '#' x $count, " $bank: $joltage" if $verbose;
return $joltage;
}
my @banks = $inputfile.lines;
say "Part one: ", @banks».&joltage.sum;
say "Part two: ", @banks».&joltage(12).sum;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment