Last active
December 7, 2025 14:10
-
-
Save mscha/59f04c32d76372b103358727baa5c8b2 to your computer and use it in GitHub Desktop.
Advent of Code 2025 day 7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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