day15
This commit is contained in:
parent
b34285bcf9
commit
3581d429e6
18
15/1.pl
Normal file
18
15/1.pl
Normal file
@ -0,0 +1,18 @@
|
||||
use 5.20.0;
|
||||
|
||||
use List::AllUtils qw/ pairgrep /;
|
||||
|
||||
my @v = ( 679,771 );
|
||||
|
||||
my $mask = 2**16 - 1;
|
||||
|
||||
my $match;
|
||||
for ( 1..40_000_000 ) {
|
||||
@v = ( 16807 * $v[0], 48271 * $v[1] );
|
||||
$_ %= 2147483647 for @v;
|
||||
|
||||
$match += ($v[0] & $mask) == ($v[1] & $mask);
|
||||
|
||||
}
|
||||
|
||||
say $match;
|
27
15/2.pl
Normal file
27
15/2.pl
Normal file
@ -0,0 +1,27 @@
|
||||
use 5.20.0;
|
||||
|
||||
use List::Lazy qw/ lazy_list lazy_range /;
|
||||
|
||||
my $mask = 2**16 - 1;
|
||||
|
||||
my $list_a = ( lazy_list {
|
||||
$_ *= 16_807;
|
||||
$_ %= 2147483647;
|
||||
$_;
|
||||
} 679 )->grep( sub { not $_ % 4 } )->map(sub{ $_ & $mask });
|
||||
|
||||
my $list_b = ( lazy_list {
|
||||
$_ *= 48_271;
|
||||
$_ %= 2147483647;
|
||||
$_;
|
||||
} 771 )->grep( sub { not $_ % 8 } )->map(sub{ $_ & $mask });
|
||||
|
||||
|
||||
use DDP;
|
||||
my $i = 0;
|
||||
say $list_a
|
||||
->until(sub{ ++$i >= 5_000_000})
|
||||
->spy(sub { say $i unless $i % 100_000 })
|
||||
->grep(sub { $_ == $list_b->next } )
|
||||
->reduce(sub { $a + 1},0);
|
||||
|
2
15/input.txt
Normal file
2
15/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Generator A starts with 679
|
||||
Generator B starts with 771
|
Loading…
Reference in New Issue
Block a user