diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2022-01-11 17:48:03 -0500 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2022-01-11 17:48:03 -0500 |
| commit | 9b1f239ffecd7923ede7ba8d965939fd08fb5661 (patch) | |
| tree | dcd5be81de6b5dc46ce5ff310611edef3692155e | |
| parent | f5f9c8a7c5b5e6e640c6e52579878e0ed5cc97fa (diff) | |
| download | perlweeklychallenge-club-9b1f239ffecd7923ede7ba8d965939fd08fb5661.tar.gz perlweeklychallenge-club-9b1f239ffecd7923ede7ba8d965939fd08fb5661.tar.bz2 perlweeklychallenge-club-9b1f239ffecd7923ede7ba8d965939fd08fb5661.zip | |
Revise and extend my code, added blog
| -rw-r--r-- | challenge-147/dave-jacoby/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-147/dave-jacoby/perl/ch-1.pl | 4 | ||||
| -rw-r--r-- | challenge-147/dave-jacoby/perl/ch-2.pl | 8 |
3 files changed, 6 insertions, 7 deletions
diff --git a/challenge-147/dave-jacoby/blog.txt b/challenge-147/dave-jacoby/blog.txt new file mode 100644 index 0000000000..e386698c3c --- /dev/null +++ b/challenge-147/dave-jacoby/blog.txt @@ -0,0 +1 @@ +https://jacoby.github.io/2022/01/11/truncations-and-pentagons-the-weekly-challenge-147.html
\ No newline at end of file diff --git a/challenge-147/dave-jacoby/perl/ch-1.pl b/challenge-147/dave-jacoby/perl/ch-1.pl index edc998ee77..197c72f5b7 100644 --- a/challenge-147/dave-jacoby/perl/ch-1.pl +++ b/challenge-147/dave-jacoby/perl/ch-1.pl @@ -11,7 +11,7 @@ my $c = 1; my $n = 2; while (1) { - if ( is_prime($n) ) { + if ( $n !~ /0/mx && is_prime($n) ) { $primes{$n}++; my $copy = $n; while ( length $copy > 0 ) { @@ -22,7 +22,7 @@ while (1) { last; } } - last if scalar keys %trunc > 20; + last if scalar keys %trunc > 30; } $n++; } diff --git a/challenge-147/dave-jacoby/perl/ch-2.pl b/challenge-147/dave-jacoby/perl/ch-2.pl index 4385f57450..61f3b1b1d6 100644 --- a/challenge-147/dave-jacoby/perl/ch-2.pl +++ b/challenge-147/dave-jacoby/perl/ch-2.pl @@ -5,16 +5,16 @@ use warnings; use feature qw{ say postderef signatures state }; no warnings qw{ experimental }; -my $top = 100_000; +my $top = 10_000; my @pentagon = map { pentagon($_) } 0 .. $top; my %pentagon = map { $_ => 1 } @pentagon; +delete $pentagon{0}; for my $i ( 1 .. $top ) { - for my $j ( 1 .. $i - 1 ) { + for my $j ( 1 .. $i ) { my $pi = $pentagon[$i]; my $pj = $pentagon[$j]; my $sum = $pi + $pj; - if ( $pentagon{$sum} ) { my $product = abs( $pi - $pj ); if ( $pentagon{$product} ) { @@ -25,10 +25,8 @@ for my $i ( 1 .. $top ) { abs( $pi - $pj ) = $product END exit; - } } - } } |
