diff options
| author | Ian Rifkin <ian.p.rifkin@gmail.com> | 2020-02-18 23:00:00 -0500 |
|---|---|---|
| committer | Ian Rifkin <ian.p.rifkin@gmail.com> | 2020-02-18 23:00:00 -0500 |
| commit | 7c629cb6ff8b98c1e38bdeb5b5d1c23e8bc6f132 (patch) | |
| tree | a4b7fadb44dd7791aa52c8ef55598f7183246180 | |
| parent | 3aad5eea0347f5e7f74a24cd382f369bd5b3db56 (diff) | |
| download | perlweeklychallenge-club-7c629cb6ff8b98c1e38bdeb5b5d1c23e8bc6f132.tar.gz perlweeklychallenge-club-7c629cb6ff8b98c1e38bdeb5b5d1c23e8bc6f132.tar.bz2 perlweeklychallenge-club-7c629cb6ff8b98c1e38bdeb5b5d1c23e8bc6f132.zip | |
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++ +} |
