AoC 2023, day 8

Run Settings
LanguageRaku
Language Version
Run Command
sub solve(@ins, %nodes, \from --> UInt:D) { my ($nn, $node, $cnt) = +@ins, from, 0; $node = %nodes{$node}{@ins[$cnt++ mod $nn]} while $node.substr(2,1) ne 'Z'; $cnt } my ($instruction, $nodes) = $*IN.slurp.split("\n\n"); my @ins = $instruction.comb; my %nodes = $nodes.lines.map({ my @a = .comb(/\w\w\w/); @a[0] => (:L(@a[1]), :R(@a[2])).Hash }); my @start-nodes = %nodes.keys.grep(/A$/); put 'part 1: ', solve(@ins, %nodes, 'AAA') if 'AAA' (elem) @start-nodes; put 'part 2: ', [lcm] @start-nodes.map({ solve(@ins, %nodes, $_) }) if +@start-nodes > 1;
Editor Settings
Theme
Key bindings
Full width
Lines