PWC 179
PWC 179
These are somewhat quick and dirty attempts as I have less spare time this week.
Challenge 1 (ordinal numbers)
Challenge 1 asks for a numeric input to be represented in words (in English) as an ordinal number, e.g., 62 -> sixty-second.
The easiest way to do this in Perl 5 is via the Lingua::EN::Numbers package or one of its relatives. The ready-made num2en_ordinal subroutine does what we need.
In Raku, it is easiest to use Lingua::EN::Numbers again via Inline::Perl 5.
In Julia too, I just run Perl 5 one-liners using Julia's backtick notation (documented here).
So effectively I have three Perl 5 scripts wrapped slightly differently.
Challenge 2 (Unicode sparkline)
Sparklines are inline graphics. We are asked to represent an array of numbers as a sparkline using unicode characters.
I use the three unicode characters ▂ ▁ and ▃ to represent items in the array that are respectively within one standard deviation of the median (▂), more than one standard deviation less than the median (▁) i.e., in the left tail, or more than one standard deviation greater than the median (▃), i.e., in the right tail.
So for the array of numbers (1,2,3,4,5,4,3,2,1), my programs print out: ▁▂▂▂▃▂▂▂▁.
Comments