Interestingly, the Perl 5 and Perl 6 solutions to Challenge 24 task 1 in the Perl Weekly Challenge are identical.
This week’s Perl Weekly Challenge, problem 1, reads:
The numbers formed by adding one to the products of the smallest primes are called the Euclid Numbers (see wiki). Write a script that finds the smallest Euclid Number that is not prime. This challenge was proposed by Laurent Rosenfeld.
The first Euclid numbers are 3, 7, and 31. These are computed as follows:
We’ll take the first three prime numbers – 2, 3, and 5.
The corresponding Euclid number is the prime number multiplied by all the smaller prime numbers, with 1 added to it.
So the first one, 3, is just 2 (nothing to multiply it against) plus 1.
The second one is 3 * 2 plus 1, or 7.
The third one is 5 * 3 *2 + 1, which is 31.
How do you do this in code? Continue reading
This week’s (week 10) Perl Request Challenge, challenge 1, was:
Write a script to encode/decode Roman numerals. For example, given Roman numeral CCXLVI, it should return 246. Similarly, for decimal number 39, it should return XXXIX. Checkout wikipedia page for more informaiton.
For this blog, I’m going to talk about converting a decimal to a Roman numeral.
To start with, I read the Wikipedia page referenced in the challenge, and realized there were several different systems for writing Roman numerals – it wasn’t as standardized as I thought! That said, I stuck with the style used in the description of the challenge, specifically “subtractive” notation. Essentially, the symbols are written from the largest value to the smallest value, left to right, with no more than 3 of any symbol used. When four of a symbol would normally be used (for instance, IIII to mean 4), instead it would be written as IV, meaning one less than 4 (you see this because the smaller number is before the bigger number).
So that’s what I’ll talk about below – the part of the code that converts an integer to a Roman number.
The Perl Weekly Challenge for week 9 includes an optional third challenge – essentially, use the Sparkpost service’s API to send an email. Sparkpost is a service that allows sending emails via an HTTP interface, just by posting a JSON form response.
I’ve noticed people have not known how to solve these API-usage challenges, so I will share my method of solving them, using Perl 6.