Skip to content

Instantly share code, notes, and snippets.

@mscha
Last active December 11, 2024 15:33
Show Gist options
  • Save mscha/f285e3d052b828ff015cd59d467802dc to your computer and use it in GitHub Desktop.
Save mscha/f285e3d052b828ff015cd59d467802dc to your computer and use it in GitHub Desktop.
Advent of Code 2024 day 11
#!/usr/bin/env raku
use v6.d;
$*OUT.out-buffer = False; # Autoflush
# Advent of Code 2024 day 11 -- https://adventofcode.com/2024/day/11
sub split-in-half($n) { $n.comb(/\w ** { $n.chars div 2 }/)».Int }
use experimental :cached;
multi blink($stone, $times) is cached
{
return 1 if $times == 0;
my @new-stones = do given $stone {
when 0 { 1 }
when .chars %% 2 { split-in-half($_) }
default { $_ × 2024 }
}
return blink(@new-stones, $times-1).sum;
}
multi blink(@stones, $times) { @stones».&blink($times).sum }
sub MAIN(IO() $inputfile where *.f = 'aoc11.input')
{
my @stones = $inputfile.words».Int;
say "Part 1: ", blink(@stones, 25);
say "Part 2: ", blink(@stones, 75);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment