aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Wilson <steven1170@zoho.eu>2020-02-22 18:33:40 +0000
committerSteven Wilson <steven1170@zoho.eu>2020-02-22 18:33:40 +0000
commiteccffc6d9322abdaa7cfc4ff4ecf75c409c6de34 (patch)
treef40f8f5c216a0fe075e4f172b8396a192248306b
parent21446a2dca5cea394700e161dd0e33a8005cb4dc (diff)
downloadperlweeklychallenge-club-eccffc6d9322abdaa7cfc4ff4ecf75c409c6de34.tar.gz
perlweeklychallenge-club-eccffc6d9322abdaa7cfc4ff4ecf75c409c6de34.tar.bz2
perlweeklychallenge-club-eccffc6d9322abdaa7cfc4ff4ecf75c409c6de34.zip
week 48 solutions
-rw-r--r--challenge-048/steven-wilson/perl/ch-01.pl34
-rw-r--r--challenge-048/steven-wilson/perl/ch-02.pl68
2 files changed, 102 insertions, 0 deletions
diff --git a/challenge-048/steven-wilson/perl/ch-01.pl b/challenge-048/steven-wilson/perl/ch-01.pl
new file mode 100644
index 0000000000..dcf7ac42c3
--- /dev/null
+++ b/challenge-048/steven-wilson/perl/ch-01.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/env perl
+# Steven Wilson
+# Challenge 048 Task #1
+# 22 Feb 2020
+
+# 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 strict;
+use warnings;
+use feature qw/ say /;
+
+my @circle = 1 .. 50;
+my $position = 1;
+
+while ( scalar @circle > 1 ) {
+ if ( $position > scalar @circle ) {
+ $position = 0;
+ }
+ splice @circle, $position, 1;
+ $position++;
+}
+
+say "Survivor is at position $circle[0]";
+
+# Output:
+# Survivor is at position 31
diff --git a/challenge-048/steven-wilson/perl/ch-02.pl b/challenge-048/steven-wilson/perl/ch-02.pl
new file mode 100644
index 0000000000..775da11d51
--- /dev/null
+++ b/challenge-048/steven-wilson/perl/ch-02.pl
@@ -0,0 +1,68 @@
+#!/usr/bin/env perl
+# Steven Wilson
+# Challenge 048 Task #2
+# 22 Feb 2020
+
+# 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 strict;
+use warnings;
+use feature qw/ say /;
+use DateTime;
+
+my $year = 2000;
+
+while ( $year < 3000 ) {
+ eval {
+ my $dt = DateTime->new(
+ year => $year,
+ month => substr( $year, -1, 1 ) . ( substr $year, -2, 1 ),
+ day => substr( $year, -3, 1 ) . ( substr $year, -4, 1 ),
+ );
+ my $reay = reverse $year;
+ say "$reay$year";
+ };
+ $year++;
+}
+
+# Output:
+# 10022001
+# 01022010
+# 11022011
+# 02022020
+# 12022021
+# 03022030
+# 04022040
+# 05022050
+# 06022060
+# 07022070
+# 08022080
+# 09022090
+# 10122101
+# 01122110
+# 11122111
+# 02122120
+# 12122121
+# 03122130
+# 04122140
+# 05122150
+# 06122160
+# 07122170
+# 08122180
+# 09122190
+# 10222201
+# 01222210
+# 11222211
+# 02222220
+# 12222221
+# 03222230
+# 04222240
+# 05222250
+# 06222260
+# 07222270
+# 08222280
+# 09222290