Advertisement
musifter

AoC day 13 (pt1), Perl

Dec 13th, 2020
1,363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.32 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my $time  = <>; chomp $time;
  7. my @buses = grep { $_ ne 'x' } map { chomp; split /,/ } <>;
  8. my %next  = map { $_ => ($_ - $time % $_) } @buses;
  9.  
  10. my $part1;
  11. foreach my $k (sort { $next{$a} <=> $next{$b} } keys %next) {
  12.     $part1 //= $k * $next{$k};
  13. }
  14.  
  15. print "Part 1: $part1\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement