diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-03-15 04:18:55 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-15 04:18:55 +0000 |
| commit | eeee9a641fa27dbd7073b5e434752aa68738c138 (patch) | |
| tree | 446a3aa1d52871fc26946bcc9142c46b112ce6af | |
| parent | e4fb6efd51e2972432ed8a96a65d262bd50b7b68 (diff) | |
| parent | 8de9c5ab6684ebd1ebaecf1d7e83186278f5ded6 (diff) | |
| download | perlweeklychallenge-club-eeee9a641fa27dbd7073b5e434752aa68738c138.tar.gz perlweeklychallenge-club-eeee9a641fa27dbd7073b5e434752aa68738c138.tar.bz2 perlweeklychallenge-club-eeee9a641fa27dbd7073b5e434752aa68738c138.zip | |
Merge pull request #3722 from PerlBoy1967/branch-for-challenge-103
Task 1 & 2
| -rw-r--r-- | challenge-103/perlboy1967/perl/MercuryTheatre.info | 7 | ||||
| -rwxr-xr-x | challenge-103/perlboy1967/perl/ch-1.pl | 33 | ||||
| -rwxr-xr-x | challenge-103/perlboy1967/perl/ch-2.pl | 67 |
3 files changed, 107 insertions, 0 deletions
diff --git a/challenge-103/perlboy1967/perl/MercuryTheatre.info b/challenge-103/perlboy1967/perl/MercuryTheatre.info new file mode 100644 index 0000000000..9428b93004 --- /dev/null +++ b/challenge-103/perlboy1967/perl/MercuryTheatre.info @@ -0,0 +1,7 @@ +1709363,"Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)" +1723781,"Les Miserables Episode 2: Javert (broadcast date: 1937-07-30)" +1723781,"Les Miserables Episode 3: The Trial (broadcast date: 1937-08-06)" +1678356,"Les Miserables Episode 4: Cosette (broadcast date: 1937-08-13)" +1646043,"Les Miserables Episode 5: The Grave (broadcast date: 1937-08-20)" +1714640,"Les Miserables Episode 6: The Barricade (broadcast date: 1937-08-27)" +1714640,"Les Miserables Episode 7: Conclusion (broadcast date: 1937-09-03)" diff --git a/challenge-103/perlboy1967/perl/ch-1.pl b/challenge-103/perlboy1967/perl/ch-1.pl new file mode 100755 index 0000000000..8eb99a8842 --- /dev/null +++ b/challenge-103/perlboy1967/perl/ch-1.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +# Perl Weekly Challenge - 103 +# - https://perlweeklychallenge.org/blog/perl-weekly-challenge-103/#TASK1 +# +# Task 1 - Chinese zodiac +# +# Author: Niels 'PerlBoy' van Dijke +# +# Note: Assuming to print the Zodiac sign for Jan 1st + +use v5.16; +use strict; +use warnings; + +my @animalCycle = qw( + Rat Ox Tiger Rabbit Dragon Snake + Horse Goat Monkey Rooster Dog Pig +); +my @elementCycle = qw( + Wood Fire Earth Metal Water +); + +@ARGV = (2021) + unless (scalar @ARGV); + +my $YEAR = shift; + +printf "Input: %d\n", $YEAR; +printf "Output: %s %s\n", + $elementCycle[int(($YEAR+6)/2)%5], + $animalCycle[($YEAR+8)%12]; + diff --git a/challenge-103/perlboy1967/perl/ch-2.pl b/challenge-103/perlboy1967/perl/ch-2.pl new file mode 100755 index 0000000000..74f4d983e3 --- /dev/null +++ b/challenge-103/perlboy1967/perl/ch-2.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl + +# Perl Weekly Challenge - 103 +# - https://perlweeklychallenge.org/blog/perl-weekly-challenge-103/#TASK2 +# +# Task 2 - What’s playing? +# +# Author: Niels 'PerlBoy' van Dijke +# + +use v5.16; +use strict; +use warnings; + +# Prototypes +sub readPlayList($); + +@ARGV = ( + 1606134123, + 1614591276, + 'MercuryTheatre.info' +); + +my ($START, $CURRENT, $FILE) = @ARGV; + +my $elapsedTimeMs = ($CURRENT - $START) * 1000; + +printf "start time : %d (%s)\n", $START, scalar localtime($START); +printf "current time: %d (%s)\n", $CURRENT, scalar localtime($CURRENT); + +my ($arPlayList, $playListDurationMs) = readPlayList($FILE); + +my $inPlaylistMs = $elapsedTimeMs % $playListDurationMs; + +my $i = 0; +while ($inPlaylistMs >= $arPlayList->[$i][0]) { + $inPlaylistMs -= $arPlayList->[$i++][0]; +} +my $inNumberS = int($inPlaylistMs / 1000); + +printf "Playing: '%s'\n", $arPlayList->[$i][1]; +printf "%02d:%02d:%02d\n", + int($inNumberS / 3600), + int($inNumberS / 60) % 60, + $inNumberS % 60; + + +sub readPlayList($) { + my ($filename) = @_; + + my @playList; + my $playListDuration = 0; + + if (!open(FH,"< $filename")) { + die "Can't open '$filename' ($!)"; + } else { + while (<FH>) { + s/#.*//; + if (/^\s*(\d+)\s*,\s*"(.*?)"\s*$/) { + push(@playList,[$1,$2]); + $playListDuration += $1; + } + } + close(FH); + } + return (\@playList, $playListDuration); +} |
