diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-03-03 18:28:12 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-03 18:28:12 +0000 |
| commit | 0746d2f415e4eb9571b6015f2ac9acaa9ff49411 (patch) | |
| tree | a626739db517d3e543c81929dbd2f24124312572 | |
| parent | d7ca7d1588137ee665913624b1f1f5c83da4bc2d (diff) | |
| parent | 4f57e541be832d855212c2b94015e24af66f986d (diff) | |
| download | perlweeklychallenge-club-0746d2f415e4eb9571b6015f2ac9acaa9ff49411.tar.gz perlweeklychallenge-club-0746d2f415e4eb9571b6015f2ac9acaa9ff49411.tar.bz2 perlweeklychallenge-club-0746d2f415e4eb9571b6015f2ac9acaa9ff49411.zip | |
Merge pull request #3654 from Doomtrain14/master
perl solution ch#100-1
| -rw-r--r-- | challenge-102/yet-ebreo/perl/ch-1.pl | 25 | ||||
| -rw-r--r-- | challenge-102/yet-ebreo/perl/ch-1a.pl | 27 |
2 files changed, 52 insertions, 0 deletions
diff --git a/challenge-102/yet-ebreo/perl/ch-1.pl b/challenge-102/yet-ebreo/perl/ch-1.pl new file mode 100644 index 0000000000..b856e86a8e --- /dev/null +++ b/challenge-102/yet-ebreo/perl/ch-1.pl @@ -0,0 +1,25 @@ +#! /usr/bin/perl + +use strict; +use warnings; +use feature qw(say); + +my $N = $ARGV[0] || 2; + +#Short but ineffecient, fails N = 9 +my @rares = grep{($_-reverse>-1)&&sqrt($_+reverse)!~/\./&&sqrt($_-reverse)!~/\./}10**~-$N..~-10**$N; +say "Rare with $N digits: @rares" + +# =begin +# Rare with 1 digits: 2 8 +# Rare with 2 digits: 65 +# Rare with 3 digits: 242 +# Rare with 4 digits: +# Rare with 5 digits: 20402 24642 +# Rare with 6 digits: 621770 +# Rare with 7 digits: 2004002 2138312 2468642 +# Rare with 8 digits: 85099058 +# Rare with 9 digits: Killed! +# =cut + + diff --git a/challenge-102/yet-ebreo/perl/ch-1a.pl b/challenge-102/yet-ebreo/perl/ch-1a.pl new file mode 100644 index 0000000000..e82ec2c9d4 --- /dev/null +++ b/challenge-102/yet-ebreo/perl/ch-1a.pl @@ -0,0 +1,27 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +my $N = $ARGV[0] || 2; +my @rn; + +#Some optimization, still inefficient, was able to solve N = 9, took a long while +for my $base (2,4,6,8) { + for my $r (0..~-10**~-$N) { + $_ = $base*10**~-$N+$r; + ($_-reverse>-1)&&sqrt($_+reverse)!~/\./&&sqrt($_-reverse)!~/\./ && (push @rn,$_) + } +} +print "Rare with $N digits: @rn\n"; +# =begin +# Rare with 1 digits: 2 8 +# Rare with 2 digits: 65 +# Rare with 3 digits: 242 +# Rare with 4 digits: +# Rare with 5 digits: 20402 24642 +# Rare with 6 digits: 621770 +# Rare with 7 digits: 2004002 2138312 2468642 +# Rare with 8 digits: 85099058 +# Rare with 9 digits: 200040002 204060402 242484242 281089082 291080192 +# =cut
\ No newline at end of file |
