From 17819b37061916eb8e8d5cafee65df39cd82980a Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 15 Mar 2021 14:18:10 +0100 Subject: Perl solution for week 104, part 1 --- challenge-104/abigail/README.md | 1 + challenge-104/abigail/perl/ch-1.pl | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 challenge-104/abigail/perl/ch-1.pl 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"; -- cgit