2025 AoC Day 11 – Reactor

This is a solution to Advent of Code 2025 day 11, written in Raku.

https://adventofcode.com/2025/day/11

Part One

How many different paths lead from you to out?

use Test;

sub part-one($input) {
    my %attachments = $input.IO.lines.map(
                          -> $line {
                              my @labels = $line.comb(/\w+/);
                              @labels[0] => @labels[1..*]
                          });

    sub paths($label) {
        return 1 if $label eq 'out';
        my @subs = gather {
            for %attachments{$label}.List -> $attach-label {
                take paths($attach-label);
            }
        }
        return [+] @subs;
    }

    paths('you')
}

is part-one('11-test.txt'), 5, 'test input';
{
    say part-one('11-input.txt');
    say "Took " ~ (now - ENTER now).base(10,2) ~ " seconds";
}
ok 1 - test input
708
Took 0.05 seconds

Part Two

Find all of the paths that lead from svr to out. How many of those paths visit both dac and fft?

use Test;

sub part-two($input) {
    my %attachments = $input.IO.lines.map(
                          -> $line {
                              my @labels = $line.comb(/\w+/);
                              @labels[0] => @labels[1..*]
                          });

    my %seen = out => 1, outdacfft => 0, outdac => 0, outfft => 0;
    sub paths($label, @need) {
        my $key = ($label, |@need).join;
        return %seen{$key} if %seen{$key}:exists;

        my @subs = %attachments{$label}.map(
            -> $attach-label {
                my @still-need = (@need (-) $label).keys.sort.Array;
                paths($attach-label, @still-need);
            });
        %seen{$key} = [+] @subs;
        return %seen{$key}
    }

    paths('svr', <dac fft>)
}

is part-two('11-test-p2.txt'), 2, 'test input';
{
    say "Part two: ", part-two('11-input.txt');
    say "Took " ~ (now - ENTER now).base(10,2) ~ " seconds";
}
ok 1 - test input
Part two: 545394698933400
Took 0.12 seconds
raku