diff options
| author | Abigail <abigail@abigail.freedom.nl> | 2022-02-28 20:13:26 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.freedom.nl> | 2022-02-28 20:13:26 +0100 |
| commit | 802900d8ecf73dbb3a6af80fb9418add808db90b (patch) | |
| tree | b62790b4a3c1952a3a1d1f2fea6433599a0eee62 | |
| parent | dae6f5dd2e8e47cb5738aa1a716d1f3cd181b31d (diff) | |
| download | perlweeklychallenge-club-802900d8ecf73dbb3a6af80fb9418add808db90b.tar.gz perlweeklychallenge-club-802900d8ecf73dbb3a6af80fb9418add808db90b.tar.bz2 perlweeklychallenge-club-802900d8ecf73dbb3a6af80fb9418add808db90b.zip | |
Week 154: Perl solutions.
| -rw-r--r-- | challenge-154/abigail/perl/ch-1.pl | 31 | ||||
| -rw-r--r-- | challenge-154/abigail/perl/ch-2.pl | 70 |
2 files changed, 101 insertions, 0 deletions
diff --git a/challenge-154/abigail/perl/ch-1.pl b/challenge-154/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..e60d3df7a1 --- /dev/null +++ b/challenge-154/abigail/perl/ch-1.pl @@ -0,0 +1,31 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-154 +# + +# +# Run as: perl ch-1.pl < input-file +# + +# +# Create a hash with all possible permutation as key, delete the +# ones from the input, print what remains. We make use of the fact +# that "PERL" doesn't have duplicate letters. +# + +my %all; + @all {grep {!/(.).*\g{1}/} glob "{P,E,R,L}" x 4} = (); +delete @all {map {chop; $_} <>}; +say for keys %all; + +__END__ diff --git a/challenge-154/abigail/perl/ch-2.pl b/challenge-154/abigail/perl/ch-2.pl new file mode 100644 index 0000000000..4a691a2da6 --- /dev/null +++ b/challenge-154/abigail/perl/ch-2.pl @@ -0,0 +1,70 @@ +#!/opt/perl/bin/perl + +use 5.032; + +no strict; +no warnings; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-154 +# + +# +# Run as: perl ch-2.pl +# + +# +# Seriously? If you cannot come with anything remotely new, just shut +# down the weekly challenge. +# +# Once again, we're asked to +# 1) produce the first N numbers of an OEIS sequence, with N fixed +# 2) a trivial recurrence +# 3) filter on/use prime numbers +# +# We did 1) recently in challenge 153-1, 150-2, 148-1, 147-1, 144-1, 133-2, etc +# +# We did 2) recently in challenge 150-1, 149-1, 147-2, 144-2, 136-2, etc +# +# We did 3) recently in challenge 150-2, 147-1, 146-1, 144-1, 141-1, etc +# + +# +# This is just sequence A100891 +# + +# +# To find out whether a number is prime, we could use +# +# Math::Util::Prime, but we have seen this a gazillion times recently +# in the Colins weekly review. We could use trial division, but we +# have seen that one a gazillion times in the same review as well. +# Same with using a sieve. +# +# It'll be fucking boring to see the same copy and pasted code over +# and over again. +# +# So, today, we'll do something different. To check if a number N is prime, +# we randomly pick a number d, 2 <= d < N, and see if it divides N. If it +# does, N is not prime. If not, we pick a different number, until we either +# have found N to be composite, or we have picked all N - 3 different numbers. +# +# We also won't be generating the Padovan number using a recurrence. +# Instead, we'll just count upwards, and check if we encountered a +# Padovan number. +# +# Efficient? No, not at all. But better than falling asleep reading the +# same solutioons we seen many times before over and over again. +# +# You might get a cup of tea when running this program. Better, get two cups. +# +# Oh, and we cram the entire program in just three lines. Just to make the +# challenge a bit interesting. +# + +sub _($n){%;=();while(%;<$n-2){$n%($;=2+int(rand($n-2)))||return;$;{$;}=1}1} +($-,$:,@:)=(10,(1)x3,2); +++$:&&($:==$:[-2]+$:[-3])&&(push@:,$:)&&_($:)&&say($:)&&$---while$- |
