aboutsummaryrefslogtreecommitdiff
path: root/challenge-048/jo-37/perl
diff options
context:
space:
mode:
authorJörg Sommrey <28217714+jo-37@users.noreply.github.com>2023-03-31 21:15:53 +0200
committerJörg Sommrey <28217714+jo-37@users.noreply.github.com>2023-04-19 18:48:48 +0200
commit272ebe60462117f69703b6fab517eadb8ed43f81 (patch)
tree3767e7c7299a35a80baa1b829b1c531f9c784ecd /challenge-048/jo-37/perl
parent4424cca8a2309a48cf5bcafddec0270446e11cad (diff)
downloadperlweeklychallenge-club-272ebe60462117f69703b6fab517eadb8ed43f81.tar.gz
perlweeklychallenge-club-272ebe60462117f69703b6fab517eadb8ed43f81.tar.bz2
perlweeklychallenge-club-272ebe60462117f69703b6fab517eadb8ed43f81.zip
Challenge 048 task 1
Diffstat (limited to 'challenge-048/jo-37/perl')
-rwxr-xr-xchallenge-048/jo-37/perl/ch-1.pl36
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-048/jo-37/perl/ch-1.pl b/challenge-048/jo-37/perl/ch-1.pl
new file mode 100755
index 0000000000..368fbc27cf
--- /dev/null
+++ b/challenge-048/jo-37/perl/ch-1.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/perl -s
+
+use v5.16;
+use warnings;
+use experimental 'signatures';
+
+our $help;
+
+die <<EOS if $help;
+usage: $0 [-help] [N]
+
+-help
+ print this help text
+
+N
+ find the survivor out of N
+
+EOS
+
+
+### Input and Output
+
+say survivor(shift // 50);
+
+
+### Implementation
+#
+# Instead of a circle, we consider a row where the first is moved to the
+# end in each step.
+
+sub survivor ($n) {
+ my @row = (1 .. $n);
+ push @row, (splice @row, 0, 2)[0] while @row > 1;
+
+ $row[0];
+}