diff options
| -rw-r--r-- | challenge-030/adam-russell/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-030/adam-russell/perl5/ch-1.pl | 19 | ||||
| -rw-r--r-- | challenge-030/adam-russell/perl5/ch-2.pl | 41 |
3 files changed, 61 insertions, 0 deletions
diff --git a/challenge-030/adam-russell/blog.txt b/challenge-030/adam-russell/blog.txt new file mode 100644 index 0000000000..de77098d13 --- /dev/null +++ b/challenge-030/adam-russell/blog.txt @@ -0,0 +1 @@ +https://adamcrussell.livejournal.com/10331.html diff --git a/challenge-030/adam-russell/perl5/ch-1.pl b/challenge-030/adam-russell/perl5/ch-1.pl new file mode 100644 index 0000000000..e0a451defb --- /dev/null +++ b/challenge-030/adam-russell/perl5/ch-1.pl @@ -0,0 +1,19 @@ +use strict; +use warnings; +## +# Write a script to list dates for Sunday Christmas between 2019 and 2100. +## +sub day_of_week{ + my($year, $month, $day) = @_; + my @month_value = (0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4); + $year-- if($month == 1 || $month == 2); + return ($year + int($year/4) - int($year/100) + int($year/400) + $month_value[$month-1] + $day) % 7 +} + +MAIN:{ + for my $year (2019 .. 2100){ + my $is_leap_year = ((($year % 4) == 0) && (($year % 100) != 0)) || (($year % 4) == 0 && ($year % 400) == 0); + my $dow = day_of_week($year, 12, 25); + print "$year\n" if $dow == 0; + } +} diff --git a/challenge-030/adam-russell/perl5/ch-2.pl b/challenge-030/adam-russell/perl5/ch-2.pl new file mode 100644 index 0000000000..850c512c25 --- /dev/null +++ b/challenge-030/adam-russell/perl5/ch-2.pl @@ -0,0 +1,41 @@ +use strict; +use warnings; +## +# 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. +## +use boolean; +use Math::Combinatorics; + +sub has_even{ + my @numbers = @_; + my @evens = grep { $_ % 2 == 0 } @numbers; + if(@evens){ + return true; + } + return false; +} + +sub sums_12{ + my @numbers = @_; + my $sum = unpack("%32I*", pack("I*", @numbers)); + if($sum == 12){ + return true; + } + return false; +} + +MAIN:{ + my $combinations = new Math::Combinatorics(count => 3, + data => [-10 .. 10] + ); + my @combination = $combinations->next_combination(); + do{ + if(has_even(@combination) and sums_12(@combination)){ + print "@combination\n"; + } + @combination = $combinations->next_combination(); + } while(@combination); +} |
