Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use v5.32;
- use warnings;
- use List::AllUtils qw(product pairwise);
- use POSIX qw(ceil floor);
- sub count_wins {
- my ($t, $d) = @_;
- $d++;
- my $upper = floor(($t + sqrt( $t*$t - 4*$d )) / 2);
- my $lower = ceil (($t - sqrt( $t*$t - 4*$d )) / 2);
- return ($upper - $lower + 1);
- }
- my @in = map { [m#(\d+)#g] } <>;
- say "Part 1: ", product pairwise { &count_wins($a,$b) } $in[0]->@*, $in[1]->@*;
- say "Part 2: ", &count_wins( map { join('', @$_) } @in );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement