diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-02-19 11:41:19 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-19 11:41:19 +0000 |
| commit | 0f3675d04fbb3b83ef077708a733f0ae9b0a9726 (patch) | |
| tree | 2a104330ecb2e478a584f558d83f069a73f5c459 | |
| parent | 3c74dc13522e3afce2463cff135d781e00204df0 (diff) | |
| parent | 7c629cb6ff8b98c1e38bdeb5b5d1c23e8bc6f132 (diff) | |
| download | perlweeklychallenge-club-0f3675d04fbb3b83ef077708a733f0ae9b0a9726.tar.gz perlweeklychallenge-club-0f3675d04fbb3b83ef077708a733f0ae9b0a9726.tar.bz2 perlweeklychallenge-club-0f3675d04fbb3b83ef077708a733f0ae9b0a9726.zip | |
Merge pull request #1280 from ianrifkin/new-branch
Submitting challenge048 - my first submission (IanRifkin)
| -rw-r--r-- | challenge-048/ianrifkin/README | 1 | ||||
| -rw-r--r-- | challenge-048/ianrifkin/perl/ch-1.pl | 37 | ||||
| -rw-r--r-- | challenge-048/ianrifkin/perl/ch-2.pl | 23 |
3 files changed, 61 insertions, 0 deletions
diff --git a/challenge-048/ianrifkin/README b/challenge-048/ianrifkin/README new file mode 100644 index 0000000000..2d26297fb9 --- /dev/null +++ b/challenge-048/ianrifkin/README @@ -0,0 +1 @@ +Solution by Ian Rifkin.
\ No newline at end of file diff --git a/challenge-048/ianrifkin/perl/ch-1.pl b/challenge-048/ianrifkin/perl/ch-1.pl new file mode 100644 index 0000000000..d1b32ec61d --- /dev/null +++ b/challenge-048/ianrifkin/perl/ch-1.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl +use strict; + +# 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. + +# Solution by ianrifkin + +my $num_people = 50; + +#create array of people +my @people; +for (1..$num_people) { + $people[$_] = $_; +} + +#give first person a sword +my $curr = shift @people; + +while (scalar(@people) > 1) { + #current person has sword + #move current person to end + my $curr = shift @people; + push @people, $curr; + + #kill next person + my $curr = shift @people; + + next; +} + + +print "\n***** The lone survivor is @people *****\n\n"; diff --git a/challenge-048/ianrifkin/perl/ch-2.pl b/challenge-048/ianrifkin/perl/ch-2.pl new file mode 100644 index 0000000000..cffaa0ac53 --- /dev/null +++ b/challenge-048/ianrifkin/perl/ch-2.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl +use strict; +use Date::Simple; + +# 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. + +# Solution by ianrifkin + +# Assumption: between 2000 and 2999 is from Jan 1st 2000 through the last day in 2999. + +my $check_date = Date::Simple->new('2000-01-01'); +my $end_date = Date::Simple->new('2999-12-31'); + +print "\nThe following dates from $check_date to $end_date are palindromes assuming the format mmddyyy:\n"; +while ($check_date <= $end_date) { + my $forwards = $check_date->format('%m%d%Y'); + my $backwards = reverse $forwards; + print "$forwards (" . $check_date->format('%m-%d-%Y') . ")\n" if $forwards == $backwards; + $check_date++ +} |
