diff options
| author | Abigail <abigail@abigail.be> | 2021-03-15 14:18:10 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-03-15 20:21:44 +0100 |
| commit | 17819b37061916eb8e8d5cafee65df39cd82980a (patch) | |
| tree | 3893423f92a09c3ba12173ef9da283e34c5131f8 | |
| parent | 67814aab0411ed46a4a33c7c0d8c0ef93e65f6fe (diff) | |
| download | perlweeklychallenge-club-17819b37061916eb8e8d5cafee65df39cd82980a.tar.gz perlweeklychallenge-club-17819b37061916eb8e8d5cafee65df39cd82980a.tar.bz2 perlweeklychallenge-club-17819b37061916eb8e8d5cafee65df39cd82980a.zip | |
Perl solution for week 104, part 1
| -rw-r--r-- | challenge-104/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-104/abigail/perl/ch-1.pl | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-104/abigail/README.md b/challenge-104/abigail/README.md index 3e6ba1fe6b..ca4e11b737 100644 --- a/challenge-104/abigail/README.md +++ b/challenge-104/abigail/README.md @@ -20,6 +20,7 @@ fixed number of numbers, we don't need do any calculations, or even handle a single if statement. A single print statement is enough. ### Solutions +* [Perl](perl/ch-1.pl) ### Blog diff --git a/challenge-104/abigail/perl/ch-1.pl b/challenge-104/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..a8c9fe1d29 --- /dev/null +++ b/challenge-104/abigail/perl/ch-1.pl @@ -0,0 +1,41 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# See ../README.md +# + +# +# Run as: perl ch-1.pl +# + +# +# This challenge is beyond simple. We're asked to output a fixed list +# of 50 numbers. We're not getting any input, so each run of the program +# is going to produce the same output. +# +# Now, if we were to be asked to produce the Nth number of the fucs +# sequence, or the first N numbers, we might have written some like +# +# sub f ($n) { +# state $c = {0 => 0, 1 => 1}; +# $$c {$n} //= $n % 2 ? f (($n - 1) / 2) + f (($n + 1) / 2) : f ($n / 2)} +# +# But since we're not asked to do anything smart, we just fetch the +# first 50 numbers from the link provided and print them. +# +# After all, the first rule of optimization is: don't calculate anything +# you don't have to calculate. +# + + +say "0 1 1 2 1 3 2 3 1 4 3 5 2 5 3 4 1 5 4 7 3 8 5 7 2 7 " . + "5 8 3 7 4 5 1 6 5 9 4 11 7 10 3 11 8 13 5 12 7 9 2 9"; |
