Raku solutions to Day Thirteen of the 2020 Advent of Code. Today's puzzle involved bus routes. Part One requires you to figure out which route id will arrive closest to a timestamp. The answer to Part Two involves identifying when an alignment of departure times across route ids will occur. #!/usr/bin/env raku use v6.d ; my ( $depart , $line ) = 'input' . IO . slurp . split ( " \n " ); $depart .= Int ; say "Part One: " ~ [*] $line . split ( ',' ) . grep ( none 'x' ) ». Int . map ({ $_ , $_ - ( $depart ) mod $_ }) . min ({ . [ 1 ] }) . flat ; # index of @l is the offset from factor my @l = $line . split ( ',' ); my ( $r , $factor ) = ( 0 , @l [ 0 ] . Int ); for 1 ..^ @l -> $i { next if @l [ $i ] eq 'x' ; $r = ( $r , { $_ + $factor } ... -> $a { ( $a + $i ) mod @l [ $i ] . Int == 0 }) . tail ; $factor *= @l [ $i ]; } say "Part Two: $r " ; Part One Given the sample inpu...
Comments
Post a Comment