diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-02-20 19:37:05 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-20 19:37:05 +0000 |
| commit | 6485efba33bea77a28f58006fd66e2d8fbd55039 (patch) | |
| tree | ad894a523b69cb242ca9ba36e309145043a68d23 /challenge-048 | |
| parent | b30d770f5fa0ac49941324a339cd4e62f35582e6 (diff) | |
| parent | 44b272354634fd522d34766fe42f20840fbf3d23 (diff) | |
| download | perlweeklychallenge-club-6485efba33bea77a28f58006fd66e2d8fbd55039.tar.gz perlweeklychallenge-club-6485efba33bea77a28f58006fd66e2d8fbd55039.tar.bz2 perlweeklychallenge-club-6485efba33bea77a28f58006fd66e2d8fbd55039.zip | |
Merge pull request #1286 from phillip-harris/branch-for-challenge-048
My submission for challenge 48
Diffstat (limited to 'challenge-048')
| -rw-r--r-- | challenge-048/phillip-harris/perl/ch-1.output.txt | 54 | ||||
| -rw-r--r-- | challenge-048/phillip-harris/perl/ch-1.pl | 44 | ||||
| -rw-r--r-- | challenge-048/phillip-harris/perl/ch-2.output.txt | 36 | ||||
| -rw-r--r-- | challenge-048/phillip-harris/perl/ch-2.pl | 29 | ||||
| -rw-r--r-- | challenge-048/phillip-harris/perl/ch2.old | 23 |
5 files changed, 186 insertions, 0 deletions
diff --git a/challenge-048/phillip-harris/perl/ch-1.output.txt b/challenge-048/phillip-harris/perl/ch-1.output.txt new file mode 100644 index 0000000000..c5c0382a6b --- /dev/null +++ b/challenge-048/phillip-harris/perl/ch-1.output.txt @@ -0,0 +1,54 @@ +P = Living person +K = Killer +V = Victim +KVPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP +P_KVPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP +P_P_KVPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP +P_P_P_KVPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP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_P_KVPP +P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_KV +K_V_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_ +P___K_V_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_ +P___P___K_V_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_ +P___P___P___K_V_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_ +P___P___P___P___K_V_P_P_P_P_P_P_P_P_P_P_P_P_P_P_P_ +P___P___P___P___P___K_V_P_P_P_P_P_P_P_P_P_P_P_P_P_ +P___P___P___P___P___P___K_V_P_P_P_P_P_P_P_P_P_P_P_ +P___P___P___P___P___P___P___K_V_P_P_P_P_P_P_P_P_P_ +P___P___P___P___P___P___P___P___K_V_P_P_P_P_P_P_P_ +P___P___P___P___P___P___P___P___P___K_V_P_P_P_P_P_ +P___P___P___P___P___P___P___P___P___P___K_V_P_P_P_ +P___P___P___P___P___P___P___P___P___P___P___K_V_P_ +V___P___P___P___P___P___P___P___P___P___P___P___K_ +____K___V___P___P___P___P___P___P___P___P___P___P_ +____P_______K___V___P___P___P___P___P___P___P___P_ +____P_______P_______K___V___P___P___P___P___P___P_ +____P_______P_______P_______K___V___P___P___P___P_ +____P_______P_______P_______P_______K___V___P___P_ +____P_______P_______P_______P_______P_______K___V_ +____K_______V_______P_______P_______P_______P_____ +____P_______________K_______V_______P_______P_____ +____P_______________P_______________K_______V_____ +____K_______________V_______________P_____________ +____V_______________________________K_____________ +12345678901234567890123456789012345678901234567890 +Person 37 survives diff --git a/challenge-048/phillip-harris/perl/ch-1.pl b/challenge-048/phillip-harris/perl/ch-1.pl new file mode 100644 index 0000000000..337299bebb --- /dev/null +++ b/challenge-048/phillip-harris/perl/ch-1.pl @@ -0,0 +1,44 @@ +#!/usr/bin/perl + +use strict; + +my $numppl = 50; + +my $ppl = "K" . "P" x ( $numppl - 1 ); +my @ppl = split //, $ppl; + +my $x = 1; +my $killer = 0; + +print "P = Living person\n"; +print "K = Killer\n"; +print "V = Victim\n"; + +while () { + + #Find next victim + until ( $ppl[$x] eq "P" ) { + $x++; + if ( $x > $numppl ) { $x = 0 } + } + $ppl[$x] = "V"; + + print @ppl; + print "\n"; + + $ppl[$x] = "_"; + + #Find next killer + until ( $ppl[$x] eq "P" ) { + $x++; + if ( $x == $killer ) { # only the killer remains + print "1234567890" x int( $numppl / 10 ) . "\nPerson "; + print $x + 1 . " survives\n"; + exit; + } + if ( $x > $numppl ) { $x = 0 } + } + $ppl[$x] = "K"; + $ppl[$killer] = "P"; + $killer = $x; +} diff --git a/challenge-048/phillip-harris/perl/ch-2.output.txt b/challenge-048/phillip-harris/perl/ch-2.output.txt new file mode 100644 index 0000000000..4eeea70ec6 --- /dev/null +++ b/challenge-048/phillip-harris/perl/ch-2.output.txt @@ -0,0 +1,36 @@ +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 diff --git a/challenge-048/phillip-harris/perl/ch-2.pl b/challenge-048/phillip-harris/perl/ch-2.pl new file mode 100644 index 0000000000..cad92cf6fa --- /dev/null +++ b/challenge-048/phillip-harris/perl/ch-2.pl @@ -0,0 +1,29 @@ +#!/usr/bin/perl +# 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. + +# My first attempt used Date::Time to add one day to a date object and check +# for palindrome on each loop but it was very slow. Generating potentially +# invalid dates with nested loops and checking date validity only when a +# palindrome is found turned out to be much faster. + +use Date::Calc qw(check_date); + +$year = 2000; +$month = 1; +$day = 1; + +for ( $year = 2000 ; $year <= 2999 ; $year++ ) { + for ( $month = 1 ; $month <= 12 ; $month++ ) { + for ( $day = 1 ; $day <= 31 ; $day++ ) { + $md = sprintf( "%02d%02d", $month, $day ); + if ( $md eq reverse($year) ) { + if ( check_date( $year, $month, $day ) ) { + print "$md$year\n"; + } + } + } + } +} diff --git a/challenge-048/phillip-harris/perl/ch2.old b/challenge-048/phillip-harris/perl/ch2.old new file mode 100644 index 0000000000..9a18a7a541 --- /dev/null +++ b/challenge-048/phillip-harris/perl/ch2.old @@ -0,0 +1,23 @@ +#!/usr/bin/perl + +#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 DateTime; + +$dt = DateTime->new( + year => 2000, + month => 1, + day => 1, +); + +until ( $md . $yr eq "12312999" ) { + $md = sprintf( "%02d%02d", $dt->month, $dt->day ); + $yr = $dt->year; + if ( $md eq reverse($yr) ) { print "$md$yr\n" } + $dt->add( days => 1 ); +} + +print "DONE!"; |
