# [Purdue-pm] Purdue Weekly Challenge solutions

Mark Senn mark at purdue.edu
Sun Oct 20 16:31:05 PDT 2019

```Perl 5 is the Perl that has been distributed for decades.
Perl 6 is a new language with the language syntax totally redesigned
and Perl 6 was totally rewritten from scratch.
Perl 5 has been renamed to Perl and Perl 6 has been renamed to Raku.

Perl Weekly Challenge 030 Raku solutions for tasks #1 and #2 are below.
The solution for task 2 has a solution written in Wolfram Language
(Mathematica is a technical computing environment inside which one
can write Wolfram Language code.)

#
# Perl Weekly Challenge - 030
#
# Mark Senn, http://engineering.purdue.edu/~mark
# October 19, 2019
#
# From
#     Write a script to list dates for Sunday Christmas
#     between 2019 and 2100.  For example, 25 Dec 2022 is Sunday.
#

# Perl 6 is in the process of being renamed Raku.
# Run using Raku v6.d;
use v6.d;

sub MAIN()
{
for (2019..2100) -> \$year  {
(Date.new(day =>25, month=>12, year=>\$year).day-of-week == 7)
and  say "25 Dec \$year";
}
}

# The program printed:
#     25 Dec 2022
#     25 Dec 2033
#     25 Dec 2039
#     25 Dec 2044
#     25 Dec 2050
#     25 Dec 2061
#     25 Dec 2067
#     25 Dec 2072
#     25 Dec 2078
#     25 Dec 2089
#     25 Dec 2095

#
# Perl Weekly Challenge - 030
#
# Mark Senn, http://engineering.purdue.edu/~mark
# October 19, 2019
#
# From
#     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.
#
# The sum of any three odd positive numbers will always be odd.  So,
# any three positive numbers that add to 12 must have at least one
# even number.  The task can be restated as
#     Write a script to print all possible series of 3 positive numbers
#     where the sum of the numbers is 12.  For example, 3,4,5.
#
# THIS WOLFRAM LANGUAGE (FORMERLY KNOWN AS MATHEMATICA) PROGRAM CAN BE USED
# TO SOLVE THIS PROGRAM:
#     s   =   Solve[i+j+k == 12 && i>0 && j>0 && k>0,  {i,j,k},  Integers];
#
#     For [t=1, t<=Length[s], t++,
#         Print[i/.s[[t,1]], ",", j/.s[[t,2]], ",", k/.s[[t,3]]];
#     ];
#
# Perl 6 is in the process of being renamed Raku.
# Run using Raku v6.d;
use v6.d;

sub MAIN()
{
for (1..10) -> \$i  {
for (1..10) -> \$j  {
for (1..10) -> \$k  {
(\$i + \$j + \$k == 12)  and  say "\$i,\$j,\$k";
}
}
}

# Optimize so we don't need to examine as many numbers.
for (1..10) -> \$i  {
for (1..12-\$i-1) -> \$j  {
for (12-\$i-\$j..10) -> \$k  {
(\$i + \$j + \$k == 12)  and  say "\$i,\$j,\$k";
}
}
}
}

# For each example, the program printed:
#     1,1,10
#     1,2,9
#     1,3,8
#     1,4,7
#     1,5,6
#     1,6,5
#     1,7,4
#     1,8,3
#     1,9,2
#     1,10,1
#     2,1,9
#     2,2,8
#     2,3,7
#     2,4,6
#     2,5,5
#     2,6,4
#     2,7,3
#     2,8,2
#     2,9,1
#     3,1,8
#     3,2,7
#     3,3,6
#     3,4,5
#     3,5,4
#     3,6,3
#     3,7,2
#     3,8,1
#     4,1,7
#     4,2,6
#     4,3,5
#     4,4,4
#     4,5,3
#     4,6,2
#     4,7,1
#     5,1,6
#     5,2,5
#     5,3,4
#     5,4,3
#     5,5,2
#     5,6,1
#     6,1,5
#     6,2,4
#     6,3,3
#     6,4,2
#     6,5,1
#     7,1,4
#     7,2,3
#     7,3,2
#     7,4,1
#     8,1,3
#     8,2,2
#     8,3,1
#     9,1,2
#     9,2,1
#     10,1,1

-mark
```