Skip to content

Instantly share code, notes, and snippets.

@mscha
Last active December 7, 2025 14:10
Show Gist options
  • Select an option

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

Select an option

Save mscha/59f04c32d76372b103358727baa5c8b2 to your computer and use it in GitHub Desktop.
Advent of Code 2025 day 7
#!/usr/bin/env raku
use v6.d;
$*OUT.out-buffer = False; # Autoflush
# Advent of Code 2025 day 7 -- https://adventofcode.com/2025/day/7
unit sub MAIN(IO() $inputfile where *.f = 'aoc07.input', Bool :v(:$verbose) = False);
my @lines = $inputfile.lines;
my $width = @lines[0].chars;
my $start-pos = @lines[0].index('S');
my @timelines = 0 xx $width; @timelines[$start-pos] = 1;
my $split-count = 0;
LINE:
for @lines.kv -> $line-no, $line {
my @splitters = $line.indices('^');
say " (splitters at @splitters[])" if @splitters && $verbose;
my @new-timelines = 0 xx $width;
for @timelines.grep(+*, :kv) -> $pos, $tl {
if $pos ∈ @splitters {
$split-count++;
@new-timelines[$pos-1] += $tl if 0 ≤ $pos-1 < $width;
@new-timelines[$pos+1] += $tl if 0 ≤ $pos+1 < $width;
}
else {
@new-timelines[$pos] += $tl;
}
}
@timelines = @new-timelines;
say "# $line-no.fmt('%3d'): ", @timelines if $verbose;
}
say "Part one: ", $split-count;
say "Part two: ", @timelines.sum;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment