aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2022-04-07 12:33:34 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2022-04-07 12:33:34 +0100
commit20ffdf0f472b18b14672347152a7611942687f76 (patch)
tree88c81d54658b3a26bcf9def78a450231264d4e5f
parent20cf091dc6f07128d9eeb0c44cce33e1ec590a7b (diff)
downloadperlweeklychallenge-club-20ffdf0f472b18b14672347152a7611942687f76.tar.gz
perlweeklychallenge-club-20ffdf0f472b18b14672347152a7611942687f76.tar.bz2
perlweeklychallenge-club-20ffdf0f472b18b14672347152a7611942687f76.zip
Add Perl solution to challenge 048
-rw-r--r--challenge-048/paulo-custodio/Makefile2
-rw-r--r--challenge-048/paulo-custodio/README1
-rw-r--r--challenge-048/paulo-custodio/perl/ch-1.pl31
-rw-r--r--challenge-048/paulo-custodio/perl/ch-2.pl19
-rw-r--r--challenge-048/paulo-custodio/t/test-1.yaml5
-rw-r--r--challenge-048/paulo-custodio/t/test-2.yaml17
6 files changed, 75 insertions, 0 deletions
diff --git a/challenge-048/paulo-custodio/Makefile b/challenge-048/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-048/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-048/paulo-custodio/README b/challenge-048/paulo-custodio/README
new file mode 100644
index 0000000000..87dc0b2fbd
--- /dev/null
+++ b/challenge-048/paulo-custodio/README
@@ -0,0 +1 @@
+Solution by Paulo Custodio
diff --git a/challenge-048/paulo-custodio/perl/ch-1.pl b/challenge-048/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..68892ad5bc
--- /dev/null
+++ b/challenge-048/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+
+# Challenge 048
+#
+# TASK #1
+# Survivor
+# There are 50 people standing in a circle in position 1 to 50. The person
+# standing at position 1 has a sword. He kills the next person i.e. standing at
+# position 2 and pass on the sword to the immediate next i.e. person standing at
+# position 3. Now the person at position 3 does the same and it goes on until
+# only one survives.
+#
+# Write a script to find out the survivor.
+
+use Modern::Perl;
+
+my @surv = (1..50);
+my $p = 0;
+while (@surv > 1) {
+ # kill next
+ if ($p >= $#surv) {
+ @surv = @surv[1..$#surv];
+ }
+ else {
+ splice(@surv, $p+1, 1);
+ }
+ # advance sword
+ $p++;
+ $p = 0 if $p >= @surv;
+}
+say @surv;
diff --git a/challenge-048/paulo-custodio/perl/ch-2.pl b/challenge-048/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..27e9fe5bc8
--- /dev/null
+++ b/challenge-048/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+
+# Challenge 048
+#
+# TASK #2
+# Palindrome Dates
+# Write a script to print all Palindrome Dates between 2000 and 2999. The format
+# of date is mmddyyyy. For example, the first one was on October 2, 2001 as it is
+# represented as 10022001.
+
+use Modern::Perl;
+use DateTime;
+
+my $dt = DateTime->new(year=>2000, month=>1, day=>1);
+while ($dt->year < 2100) {
+ my $txt = $dt->strftime("%m%d%Y");
+ say $txt if reverse($txt) eq $txt; # is palindrome
+ $dt->add(days=>1);
+}
diff --git a/challenge-048/paulo-custodio/t/test-1.yaml b/challenge-048/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..94725595bb
--- /dev/null
+++ b/challenge-048/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,5 @@
+- setup:
+ cleanup:
+ args:
+ input:
+ output: 37
diff --git a/challenge-048/paulo-custodio/t/test-2.yaml b/challenge-048/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..fdb31f1c58
--- /dev/null
+++ b/challenge-048/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,17 @@
+- setup:
+ cleanup:
+ args:
+ input:
+ output: |
+ |10022001
+ |01022010
+ |11022011
+ |02022020
+ |12022021
+ |03022030
+ |04022040
+ |05022050
+ |06022060
+ |07022070
+ |08022080
+ |09022090