[Purdue-pm] Perl Weekly Challenge - 004

Mark Senn mark at purdue.edu
Sun Apr 21 22:14:28 PDT 2019


(See my blog entry at
    https://engineering.purdue.edu/~mark/pwc-004.pdf
for the details of the following challenges.)


Challenge #1:
Write a script to output the same number of PI digits as the size of
your script.  Say, if your script size is 10, it should print
3.141592653.

Perl 6 Solution Highlights:
Find a rapidly converging series for pi and use FatRat (fat rationals)
for "infinite precision integer fractions".  I checked my code was
working by comparing it with the first 1000 digits of pi that
the Wolfram Language (Mathematica) uses.


Challenge #2
You are given a file containing a list of words (case insensitive 1 word
per line) and a list of letters.  Print each word from the file than can
be made using only letters from the list.  You can use each letter only
once (though there can be duplicates and you can use each of them once),
you don't have to use all the letters. (Disclaimer: The challenge was
proposed by Scimon Proctor).

Perl 6 Solution Highlights:
Use the Perl 6 bag data structure.  A bag is a set of which elements
occur and how many times they occur.  There is a commplete set of
bag operators.  "$word (<=) $letters" is true if all elements,
including counts, of word are in letters.


Next week's challenges are at
    https://perlweeklychallenge.org/blog/perl-weekly-challenge-005/f
I find these to be good exercises.

-mark


More information about the Purdue-pm mailing list