# usage: raku day4-part2.raku [path/to/input] (default: ../data/day4.txt) my $path = @*ARGS[0] // '../data/day4.txt'; my @c = $path.IO.lines.join.comb; my $n = @c.elems; my $answer = $n; for 1 .. $n -> $p { my %slots; my $clash = False; for 0 ..^ $n -> $i { my $cell = @c[$i]; next if $cell eq '?'; my $slot = $i % $p; $clash = True if %slots{$slot}:exists && %slots{$slot} ne $cell; %slots{$slot} = $cell; last if $clash; } if !$clash { $answer = $p; last; } } say $answer;