Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use List::AllUtils qw(true product);
- sub filter {
- my ($negate, @list) = @_;
- for (my $i = 0; @list > 1; $i++) {
- my $ones = true { $_->[$i] } @list;
- my $next = ($ones >= (@list / 2)) ^ $negate;
- @list = grep { $_->[$i] == $next } @list;
- }
- return (oct("0b" . join('', @{$list[0]})));
- }
- my @input = map { chomp; [split //] } <>;
- print "Part 2: ", (product map {&filter( $_, @input )} (0,1)), "\n";
Add Comment
Please, Sign In to add comment