Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save mscha/b9e176890822672d2f8d0dadb19e0d82 to your computer and use it in GitHub Desktop.
Advent of Code 2025 day 1
#!/usr/bin/env raku
use v6.d;
$*OUT.out-buffer = False; # Autoflush
# Advent of Code 2025 day 1 -- https://adventofcode.com/2025/day/1
class Safe
{
has Int $.modulo = 100;
has Int $.dial = $!modulo div 2;
has Bool $.slow = False;
has Bool $.verbose = False;
has Int $.zero-hits = $!dial == 0 ?? 1 !! 0;
multi method rotate(Str $move)
{
if $move ~~ m{^ (<[LR]>) (\d+) $ } {
my $dir = $0 eq 'L' ?? -1 !! 1;
my $count = +$1;
if ($!slow) {
self.rotate($dir) for ^$count;
}
else {
self.rotate($dir*$count);
}
say "Moved $move to $!dial ($!zero-hits zeroes)" if $!verbose;
}
else {
die "Invalid move: $move";
}
}
multi method rotate(Int $count)
{
$!dial = ($!dial + $count) % $!modulo;
$!zero-hits++ if $!dial == 0;
}
}
sub MAIN(IO() $inputfile where *.f = 'aoc01.input', Bool :v($verbose) = False)
{
my $safe1 = Safe.new(:$verbose);
for $inputfile.lines -> $move {
$safe1.rotate($move);
}
say "Part one: $safe1.zero-hits()";
my $safe2 = Safe.new(:slow, :$verbose);
for $inputfile.lines -> $move {
$safe2.rotate($move);
}
say "Part two: $safe2.zero-hits()";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment