aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-10-14 16:43:07 +0100
committerGitHub <noreply@github.com>2019-10-14 16:43:07 +0100
commitde992bf042156e8494f1c68585db57bba4d69d44 (patch)
tree29f07d70871c4c22656cb51fb9961437fb400e67
parente1385f4479c2f3dbfa6c82161b1946ecd8215ed5 (diff)
parente6d1d4ba81f7a93122884a5badc54cf54f834d33 (diff)
downloadperlweeklychallenge-club-de992bf042156e8494f1c68585db57bba4d69d44.tar.gz
perlweeklychallenge-club-de992bf042156e8494f1c68585db57bba4d69d44.tar.bz2
perlweeklychallenge-club-de992bf042156e8494f1c68585db57bba4d69d44.zip
Merge pull request #774 from TJLanger/branch-for-challenge-030
PWC-030 Submit
-rwxr-xr-xchallenge-030/trenton-langer/perl5/ch-1.pl90
-rwxr-xr-xchallenge-030/trenton-langer/perl5/ch-2.pl77
2 files changed, 167 insertions, 0 deletions
diff --git a/challenge-030/trenton-langer/perl5/ch-1.pl b/challenge-030/trenton-langer/perl5/ch-1.pl
new file mode 100755
index 0000000000..e0d464001b
--- /dev/null
+++ b/challenge-030/trenton-langer/perl5/ch-1.pl
@@ -0,0 +1,90 @@
+#!/mu/bin/perl -w
+use strict;
+no warnings;
+
+
+
+##################################################################################################################################################################
+##################################################################################################################################################################
+## Authorship
+##################################################################################################################################################################
+##################################################################################################################################################################
+### Project
+############# Perl Weekly Challenge - 030
+### Name
+############# ch-1.pl
+### Author
+############# Trenton Langer
+### Creation Date
+############# 20191014
+### Description
+############# Sunday Christmas List
+
+
+
+#####################################################################################################################
+#####################################################################################################################
+## PWC - 030 - Task 1
+#####################################################################################################################
+#####################################################################################################################
+#Write a script to list dates for Sunday Christmas between 2019 and 2100. For example, 25 Dec 2022 is Sunday.
+
+
+
+#####################################################################################################################
+#####################################################################################################################
+## Solution
+#####################################################################################################################
+#####################################################################################################################
+my $jan_01_2019 = "1546300800";
+my $jan_01_2100 = "4102444800";
+my $day_seconds = 24*60*60;
+my $year_seconds = 365*$day_seconds;
+
+my $time = $jan_01_2019;
+while ($time < $jan_01_2100)
+{
+ my ($sec,$min,$hour,$dayOfMonth,$month,$year,$dayOfWeek,$dayOfYear,$isDayLightSavings) = localtime($time);
+ $year += 1900;
+ my $last_year = $year - 1;
+ print "25 Dec $last_year is a Sunday\n" if($dayOfWeek == 0);
+
+ $time += $year_seconds;
+ my $extra_day = daysInAMonth(2, $year) - 28;
+ $time += $day_seconds if($extra_day);
+}
+
+
+
+#####################################################################################################################
+#####################################################################################################################
+## Subs
+#####################################################################################################################
+#####################################################################################################################
+sub daysInAMonth
+{
+ my $month = $_[0];
+ my $year = $_[1];
+
+ # Input validation
+ my %name_hash = ( "jan" => 1, "feb" => 2, "mar" => 3, "apr" => 4, "may" => 5, "jun" => 6, "jul" => 7, "aug" => 8, "sep" => 9, "oct" => 10, "nov" => 11, "dec" => 12);
+ if ($month =~ /^[a-z]+$/i) { $month = $name_hash{lc(substr($month,0,3))}; } # Convert name to number
+ elsif($month =~ /^[0-9]+$/) { $month = $month*1; } # Cast int from str to number
+ else { die "Month ($month) not understandable\n\n"; }
+ die "Year ($year) not understandable\n\n" if(!($year =~ /^[0-9]+$/)); # Blocks decimal points, negative signs, etc...
+
+ # Calc
+ my %days_hash = ( 1 => 31, 2 => 28, 3 => 31, 4 => 30, 5 => 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 31);
+ if ( $month != 2 ) { } # Not Feb, don't care about leap years
+ elsif( $year % 4 > 0 ) { } # Regular year, do nothing
+ elsif( $year % 100 > 0 ){ $days_hash{2} = 29; } # Leap Year
+ elsif( $year % 400 > 0 ){ } # Regular year, do nothing
+ else { $days_hash{2} = 29; } # Leap Year
+
+ # Return
+ return $days_hash{$month};
+}
+
+
+
+
diff --git a/challenge-030/trenton-langer/perl5/ch-2.pl b/challenge-030/trenton-langer/perl5/ch-2.pl
new file mode 100755
index 0000000000..8c877ace4c
--- /dev/null
+++ b/challenge-030/trenton-langer/perl5/ch-2.pl
@@ -0,0 +1,77 @@
+#!/mu/bin/perl -w
+use strict;
+no warnings;
+
+
+#####################################################################################################################
+#####################################################################################################################
+## Authorship
+#####################################################################################################################
+#####################################################################################################################
+### Project
+############# Perl Weekly Challenge - 030
+### Name
+############# ch-2.pl
+### Author
+############# Trenton Langer
+### Creation Date
+############# 20191014
+### Description
+############# Series of numbers equal to 12
+
+
+
+#####################################################################################################################
+#####################################################################################################################
+## PWC - 030 - Task 2
+#####################################################################################################################
+#####################################################################################################################
+#Write a script to print all possible series of 3 positive numbers,
+#where in each series at least one of the number is even and sum of the three numbers is always 12.
+
+#For example, 3,4,5.
+
+
+
+#####################################################################################################################
+#####################################################################################################################
+## Solution
+#####################################################################################################################
+#####################################################################################################################
+my %mem = ();
+print "3 Number Series that equal 12, with at least one even:\n";
+foreach my $i (1..10)
+{
+ my $remainder = 12 - $i;
+ my @options = @{break($remainder,$i)};
+ foreach my $option (@options)
+ {
+ print "\t$i,\t$option->[0],\t$option->[1]\n" if($i % 2 == 0 || $option->[0] % 2 == 0 || $option->[1] % 2 == 0);
+ }
+}
+
+
+
+#####################################################################################################################
+#####################################################################################################################
+## Subs
+#####################################################################################################################
+#####################################################################################################################
+sub break
+{
+ my $num = shift;
+ my $start = shift;
+ my @rtn = ();
+ return \@rtn unless($num > $start);
+ foreach my $i ($start..$num-1)
+ {
+ my $dif = $num - $i;
+ last if($dif < $i);
+ push @rtn, [$i, $dif];
+ }
+ return \@rtn;
+}
+
+
+
+