From mark at purdue.edu Sat Jan 8 19:07:45 2022
From: mark at purdue.edu (Mark Senn)
Date: Sat, 08 Jan 2022 22:07:45 -0500
Subject: [Purdue-pm] my Weekly Challenge solutions
Message-ID: <30086.1641697665@pier.ecn.purdue.edu>
Raku was formerly known as Perl 6.
Wolfram Language is the language that the Mathematica interactive
technical computing environment, etc. use.
My Raku and Wolfram Language solutions to
https://theweeklychallenge.org/blog/perl-weekly-challenge-146/
Task 1. Write a script to generate the 10001st prime number.
are at
https://engineering.purdue.edu/~mark/twc-146-1.pdf
"Perl Golf" is a game where one attempts to write the shortest Perl
program to accomplish some goal. The Raku NON-golf version is
41 characters; Wolfram Language NON-golf version is 20 characters.
>From https://en.wikipedia.org/wiki/Composability
A highly composable system provides components that can be [... -mark]
assembled in various combinations to satisfy specific user requirements.
I understand the next major specification of the Raku language will have
improved composability. Raku's operator and function composability is
excellent now.
My Raku solutions to
https://theweeklychallenge.org/blog/perl-weekly-challenge-146/
Task 2. Curious Fraction Tree
are at
https://engineering.purdue.edu/~mark/twc-146-2.pdf
Mark Senn, Senior Software Engineer,
Engineering Computer Network, Purdue University
From mark at purdue.edu Sun Jan 16 19:09:38 2022
From: mark at purdue.edu (Mark Senn)
Date: Sun, 16 Jan 2022 22:09:38 -0500
Subject: [Purdue-pm] The Weekly Challenge 147
Message-ID: <43169.1642388978@pier.ecn.purdue.edu>
This week's weekly challenge is at
https://theweeklychallenge.org/blog/perl-weekly-challenge-147/
My Raku solutions are at
https://engineering.purdue.edu/~mark/twc-147-1.pdf
and
https://engineering.purdue.edu/~mark/twc-147-2.pdf
Comments on some maybe interesteding Raku language stuff:
for (2 .. Inf).grep(*.is-prime).grep({! /0/}) -> $test {
SNIPPETT WHAT IT DOES
for (2 .. Inf) let $_ go from 2 to infinitiy...it doesn't compute
an infinite amount of stuff this is "lazy" and just
computes stuff as it needs it...when $test is used
the first time a new $test is computed...having
laziness is a feature I use a lot
.grep(*.is-prime) only use prime numbers
.grep({! /0/}) the prime numbers must not contain zero
-> $test put each of the primes without 0 in $test
one at a time
It is common for me to use this general setup of .grep(...),
.grep(...), .grep(...) to only pick out the wanted elements so I
don't need to put code inside the loop to pick wanted elements or
eliminate non-wanted elements.
my $p := 0, 1, 5, -> $a, $b { 2*$b - $a + 3 } ... Inf;
SNIPPET WHAT IT DOES
my $p := compute a lazy array $p[0] = 0
0, 1, 5, -> $a, $b { 2*$b - $a + 3 }
$p[0] = 0, $p[1] = 1, $p[2] = 5,
$p[3] for example, is 2*$p[2] - $p[1] + 3
... Inf; and do it lazily to infinity
(1 .. $n).map({%is-pentagonal{$p[$_]} = True});
SNIPPETT WHAT IT DOES
for (1 .. $n) let $_ go from 1 to $n
map({%is-pentagonal{$p[$_]} = True}) set the %is-petagonal hash
element $p[$_} to True
-mark
From mark at purdue.edu Sun Jan 23 18:55:11 2022
From: mark at purdue.edu (Mark Senn)
Date: Sun, 23 Jan 2022 21:55:11 -0500
Subject: [Purdue-pm] my weekly challenge answers
Message-ID: <5636.1642992911@pier.ecn.purdue.edu>
My Raku (formerly known as Perl 6) solutions to the Weekly
Challenge tasks are available.
Eban Numbers
https://engineering.purdue.edu/~mark/twc-148-1.pdf
This script generates all numbers from 1 to 100 without an 'e'.
For problems of this type I like to generate the spelled out
numbers and then print those without the letter 'e'.
Some people use (in my opinion) error-prone regular expression
tricks to do this---I prefer to generate the spelled versions of the
numbers and then print the ones that don't contain the letter 'e'.
An example of a trick could be /^[246]$/ to match all single digit
numbers that don't contain 'e'. Be careful with the number 50 it
contains a 5 ('five', with an 'e') but 50 ('fifty' doesn't contain
an 'e').
The program is short and commented. You can probably
follow it even if you don't know Raku. I think it is a good
program to demonstrate Raku.
Cardano Triplets
https://engineering.purdue.edu/~mark/twc-148-2.pdf
This script prints the first five Cardano triplets.
Cardano triplets satisy the condition
curt(a + b*sqrt(c)) + curt(a - b*sqrt(c)) = 1
where curt is the cube root function and sqrt is the square root
function.
Found two web pages that describe how to simplify this problem and
the ideas in them are the bulk of the mathematics in the blog.
The solution transforms the original problem using 18 step-by-step
steps to something that can be coded without needing sqrt or curt.
(No math class divide, subtract mystery term from both sides
simplify, complete the square and walla---there you go. It's a
step-by-step description.)
LaTeX is used to show the 18 step-by-step math steps. Wolfram
Language (Mathematica) is used to do math expansions and
simplifications. The Wolfram Language statements are shown.
The program is short and commented. You can probably understand it
even if you don't know Raku.
I try to avoid floating point math in languages except Wolfram
Language because the math is slow and inexact.
This program demonstrates a programming technique I use a lot:
loop {
if (some condition) exit loop
if (some condition) take another trip through the loop
...
# we've found what we're looking for, deal with it,
# by the time we get here we know what we have and
# don't need any ifs to sort things out
compute something
}
I use the nice short Raku statements to do the above ifs.
I think this is a good prorgam to demonstrate Raku.
-mark