[Purdue-pm] my weekly challenge answers

Mark Senn mark at purdue.edu
Sun Jan 23 18:55:11 PST 2022


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


More information about the Purdue-pm mailing list