aboutsummaryrefslogtreecommitdiff
path: root/challenge-037
diff options
context:
space:
mode:
authorYsmael Ebreo <Ysmael.Ebreo@latticesemi.com>2020-05-12 00:01:18 +0800
committerYsmael Ebreo <Ysmael.Ebreo@latticesemi.com>2020-05-12 00:01:18 +0800
commitcee596013d955ade9e0bfc7bda589b7ad74daabe (patch)
tree37f1ee31beab18e94af00bdef54bcf1f68f3e421 /challenge-037
parentb0c9decdf1f79502fd477b53289dbe9338bbf0bc (diff)
downloadperlweeklychallenge-club-cee596013d955ade9e0bfc7bda589b7ad74daabe.tar.gz
perlweeklychallenge-club-cee596013d955ade9e0bfc7bda589b7ad74daabe.tar.bz2
perlweeklychallenge-club-cee596013d955ade9e0bfc7bda589b7ad74daabe.zip
Added perl solution for ch#37
Diffstat (limited to 'challenge-037')
-rw-r--r--challenge-037/yet-ebreo/perl/ch-1.pl35
-rw-r--r--challenge-037/yet-ebreo/perl/ch-2.pl100
2 files changed, 135 insertions, 0 deletions
diff --git a/challenge-037/yet-ebreo/perl/ch-1.pl b/challenge-037/yet-ebreo/perl/ch-1.pl
new file mode 100644
index 0000000000..7b5e2360c8
--- /dev/null
+++ b/challenge-037/yet-ebreo/perl/ch-1.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use feature 'say';
+use POSIX;
+
+my $year = 2019;
+my @days = (31, 28 + is_leap($year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
+
+for my $month ( 0 .. 11 ) {
+ my $count = grep {
+ strftime( "%w", 0, 0, 0, $_+6, $month, $year - 1900 ) < 5
+ } 1 .. $days[$month];
+ say strftime( "%b", 0, 0, 0, 1, $month, $year - 1900 ) . ": $count days";
+}
+
+sub is_leap {
+ strftime("%w", 0, 0, 0, 29 , 1, $_[0] - 1900 ) ne
+ strftime("%w", 0, 0, 0, 1 , 2, $_[0] - 1900 );
+}
+=begin
+perl .\ch-1.pl
+Jan: 23 days
+Feb: 20 days
+Mar: 21 days
+Apr: 22 days
+May: 23 days
+Jun: 20 days
+Jul: 23 days
+Aug: 22 days
+Sep: 21 days
+Oct: 23 days
+Nov: 21 days
+Dec: 22 days
+=cut \ No newline at end of file
diff --git a/challenge-037/yet-ebreo/perl/ch-2.pl b/challenge-037/yet-ebreo/perl/ch-2.pl
new file mode 100644
index 0000000000..1e6847326d
--- /dev/null
+++ b/challenge-037/yet-ebreo/perl/ch-2.pl
@@ -0,0 +1,100 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use feature 'say';
+
+# Write a script to find out the DayLight gain/loss in the month of December 2019
+# as compared to November 2019 in the city of London.
+# You can find out sunrise and sunset data for November 2019 and December 2019 for London.
+my @hour_delta;
+while (<DATA>) {
+ chomp;
+ my ($day,$rise,$set) = /[^,]+/g;
+ if (defined $day && $day=~/^\d+$/ && $day < 32) {
+ $set =~ /(..):(..)/;
+ $set = $1*60+$2;
+ $rise =~ /(..):(..)/;
+ $rise = $1*60+$2;
+ if (!defined $hour_delta[$day]) {
+ $hour_delta[$day] = $set - $rise;
+ } else {
+ $hour_delta[$day] -= ($set - $rise);
+ }
+ }
+
+}
+my $total_hours;
+for my $day (1..30) {
+ $total_hours += $hour_delta[$day];
+
+ my $hours = 0|$hour_delta[$day] / 60;
+ my $mins = $hour_delta[$day] % 60;
+
+ printf ("Day %02d: Δ = %02d:%02d\n",$day, $hours, $mins);
+}
+
+__DATA__
+Nov,Sunrise,Sunset
+1,06:53,16:34
+2,06:55,16:32
+3,06:56,16:30
+4,06:58,16:28
+5,07:00,16:27
+6,07:02,16:25
+7,07:03,16:23
+8,07:05,16:22
+9,07:07,16:20
+10,07:09,16:18
+11,07:10,16:17
+12,07:12,16:15
+13,07:14,16:14
+14,07:16,16:12
+15,07:17,16:11
+16,07:19,16:10
+17,07:21,16:08
+18,07:22,16:07
+19,07:24,16:06
+20,07:26,16:05
+21,07:27,16:04
+22,07:29,16:03
+23,07:31,16:01
+24,07:32,16:00
+25,07:34,15:59
+26,07:35,15:59
+27,07:37,15:58
+28,07:38,15:57
+29,07:40,15:56
+30,07:41,15:55
+
+Dec,Sunrise,Sunset
+1,07:43,15:55
+2,07:44,15:54
+3,07:46,15:53
+4,07:47,15:53
+5,07:48,15:53
+6,07:49,15:52
+7,07:51,15:52
+8,07:52,15:51
+9,07:53,15:51
+10,07:54,15:51
+11,07:55,15:51
+12,07:56,15:51
+13,07:57,15:51
+14,07:58,15:51
+15,07:59,15:51
+16,08:00,15:51
+17,08:00,15:51
+18,08:01,15:52
+19,08:02,15:52
+20,08:02,15:52
+21,08:03,15:53
+22,08:04,15:53
+23,08:04,15:54
+24,08:04,15:54
+25,08:05,15:55
+26,08:05,15:56
+27,08:05,15:57
+28,08:06,15:57
+29,08:06,15:58
+30,08:06,15:59
+31,08:06,16:00 \ No newline at end of file