diff options
| author | Noud Aldenhoven <noud.aldenhoven@gmail.com> | 2019-10-19 09:17:26 +0200 |
|---|---|---|
| committer | Noud Aldenhoven <noud.aldenhoven@gmail.com> | 2019-10-19 09:17:26 +0200 |
| commit | bc756d9cb415b5d9772e6f3506b10c55f965f7fa (patch) | |
| tree | acf8604aa88593b2ac9801f603b7c839f7315f71 /challenge-030 | |
| parent | 45beb0d934d241d1f90e7c9c5ebe1a6baf7e05c1 (diff) | |
| download | perlweeklychallenge-club-bc756d9cb415b5d9772e6f3506b10c55f965f7fa.tar.gz perlweeklychallenge-club-bc756d9cb415b5d9772e6f3506b10c55f965f7fa.tar.bz2 perlweeklychallenge-club-bc756d9cb415b5d9772e6f3506b10c55f965f7fa.zip | |
Solutions to challenge 30 task 1 and 2 in Perl 6 by Noud
Diffstat (limited to 'challenge-030')
| -rw-r--r-- | challenge-030/noud/perl6/ch-1.p6 | 8 | ||||
| -rw-r--r-- | challenge-030/noud/perl6/ch-2.p6 | 23 |
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-030/noud/perl6/ch-1.p6 b/challenge-030/noud/perl6/ch-1.p6 new file mode 100644 index 0000000000..838e53d537 --- /dev/null +++ b/challenge-030/noud/perl6/ch-1.p6 @@ -0,0 +1,8 @@ +# Write a script to list dates for Sunday Christmas between 2019 and 2100. For +# example, 25 Dec 2022 is Sunday. + +for 2019 .. 2100 -> $year { + if (Date.new($year, 12, 25).day-of-week == 7) { + $year.say; + } +} diff --git a/challenge-030/noud/perl6/ch-2.p6 b/challenge-030/noud/perl6/ch-2.p6 new file mode 100644 index 0000000000..45efa3f42b --- /dev/null +++ b/challenge-030/noud/perl6/ch-2.p6 @@ -0,0 +1,23 @@ +# 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. + +# This should not be too hard. First notice that if (i, j, k) is a triple that +# sums up to 12, we have symetric tuples (i, k, j), (j, i, k), (j, k, i), +# (k, i, j), and (k, j, i) that also sum up to 12. We make use of this +# symmetry property. Next, if i and j are given in tuple (i, j, k), then we +# know that k = 12 - i - j. So we don't have to loop over k. Last, one of the +# integers needs to be even. Due to symmetry arguments we can always take i to +# be even. + +my $total = 12; +my @triplets = []; +for 2, 4 ... $total -> $i { + for 1 .. ($total - $i - 1) -> $j { + @triplets = [|(@triplets), |([$i, $j, $total - $i - $j].permutations)]; + } +} + +# Because we use permutations we have duplicates. Ex. (10, 1, 1) with j <-> k +# gives (10, 1, 1). +say @triplets.unique; |
