aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-122/jo-37/perl/ch-1.pl16
-rwxr-xr-xchallenge-122/jo-37/perl/ch-1a.pl13
-rwxr-xr-xchallenge-122/jo-37/perl/ch-2.pl10
3 files changed, 39 insertions, 0 deletions
diff --git a/challenge-122/jo-37/perl/ch-1.pl b/challenge-122/jo-37/perl/ch-1.pl
new file mode 100755
index 0000000000..6a94454be6
--- /dev/null
+++ b/challenge-122/jo-37/perl/ch-1.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/perl -s
+
+use v5.16;
+use warnings;
+$| = 1;
+
+# The task states "You are given a *stream* of numbers" which is taken
+# to be different from a list. Thus we expect the data to be provided
+# by a file (or STDIN), which could be a pipe.
+#
+# Call "./ch-1a.pl | ./ch-1.pl" for the task's example.
+
+my ($s, $n);
+while (<>) {
+ say +($s += $_) / ++$n;
+}
diff --git a/challenge-122/jo-37/perl/ch-1a.pl b/challenge-122/jo-37/perl/ch-1a.pl
new file mode 100755
index 0000000000..13163b50a7
--- /dev/null
+++ b/challenge-122/jo-37/perl/ch-1a.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/perl
+
+use v5.16;
+use warnings;
+$| = 1;
+
+# Provide a stream of numbers.
+
+my $n;
+while (($n += 10) < ($ARGV[0] // 100)) {
+ say $n;
+ sleep 1;
+}
diff --git a/challenge-122/jo-37/perl/ch-2.pl b/challenge-122/jo-37/perl/ch-2.pl
new file mode 100755
index 0000000000..e80538298b
--- /dev/null
+++ b/challenge-122/jo-37/perl/ch-2.pl
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+
+use v5.16;
+use warnings;
+use Math::Prime::Util 'forcomp';
+
+# The task is to list all compositions of N where each part is limited
+# to p <= 3.
+
+forcomp {say "@_"} $ARGV[0], {amax => 3};