aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-05-11 17:09:43 +0100
committerGitHub <noreply@github.com>2020-05-11 17:09:43 +0100
commitf384cb80616dd5b443f7d3e15e37cb55fc0c0192 (patch)
tree37f1ee31beab18e94af00bdef54bcf1f68f3e421
parentad67d038ef0f7baeeea8d57d3353ebcd28333a73 (diff)
parentcee596013d955ade9e0bfc7bda589b7ad74daabe (diff)
downloadperlweeklychallenge-club-f384cb80616dd5b443f7d3e15e37cb55fc0c0192.tar.gz
perlweeklychallenge-club-f384cb80616dd5b443f7d3e15e37cb55fc0c0192.tar.bz2
perlweeklychallenge-club-f384cb80616dd5b443f7d3e15e37cb55fc0c0192.zip
Merge pull request #1701 from Doomtrain14/master
Added perl solution for ch#60
-rw-r--r--challenge-037/yet-ebreo/perl/ch-1.pl35
-rw-r--r--challenge-037/yet-ebreo/perl/ch-2.pl100
-rw-r--r--challenge-060/yet-ebreo/perl/ch-1.pl57
-rw-r--r--challenge-060/yet-ebreo/perl/ch-2.pl72
4 files changed, 264 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
diff --git a/challenge-060/yet-ebreo/perl/ch-1.pl b/challenge-060/yet-ebreo/perl/ch-1.pl
new file mode 100644
index 0000000000..7c1fc0ce0b
--- /dev/null
+++ b/challenge-060/yet-ebreo/perl/ch-1.pl
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use feature 'say';
+
+sub to_num {
+ (ord) - 64 + 26 * (&to_num||0) if $_ = chop @_
+}
+sub to_exl {
+ $% = pop;
+ while ($%>26) {
+ $" = chr (64 + $% - 26*($% /= 26)) . $";
+ }
+ chr(64 + $%).$"
+}
+my $excelcol = uc ($ARGV[0]||2708874);
+
+if ($excelcol=~/\D/) {
+ say to_num($excelcol);
+} else {
+ say to_exl($excelcol);
+}
+=begin
+perl .\ch-1.pl 2708874
+EXCEL
+
+perl .\ch-1.pl 1
+A
+
+perl .\ch-1.pl A
+1
+
+perl .\ch-1.pl 26
+Z
+
+perl .\ch-1.pl Z
+26
+
+perl .\ch-1.pl 661
+YK
+
+perl .\ch-1.pl YK
+661
+
+perl .\ch-1.pl 16384
+XFD
+
+perl .\ch-1.pl XFD
+16384
+
+perl .\ch-1.pl 214358502
+RABBIT
+
+perl .\ch-1.pl RABBIT
+214358502
+
+=cut \ No newline at end of file
diff --git a/challenge-060/yet-ebreo/perl/ch-2.pl b/challenge-060/yet-ebreo/perl/ch-2.pl
new file mode 100644
index 0000000000..86162de50f
--- /dev/null
+++ b/challenge-060/yet-ebreo/perl/ch-2.pl
@@ -0,0 +1,72 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use feature 'say';
+use Algorithm::Combinatorics qw(variations_with_repetition);
+
+my @L = (0, 1, 2, 5);
+my $X = 2;
+my $Y = 21;
+if (@ARGV > 2) {
+ $Y = pop @ARGV;
+ $X = pop @ARGV;
+ @L = @ARGV;
+}
+
+say @{$_} for grep {
+ (($X == length ($% = join "",@{$_})) && ($% < $Y))
+} variations_with_repetition(\@L,$X);
+
+=begin
+perl .\ch-2.pl
+10
+11
+12
+15
+20
+
+perl .\ch-2.pl 0 1 3 9 1 5
+0
+1
+3
+
+perl .\ch-2.pl 0 1 3 9 2 20
+10
+11
+13
+19
+
+perl .\ch-2.pl 0 1 3 9 3 600
+100
+101
+103
+109
+110
+111
+113
+119
+130
+131
+133
+139
+190
+191
+193
+199
+300
+301
+303
+309
+310
+311
+313
+319
+330
+331
+333
+339
+390
+391
+393
+399
+=cut \ No newline at end of file