Perming Perl
In task 1 we were given some possible permutations of the string 'PERL' and asked for a script to find any permutations missing from the list.
I went for the easy solution of using Algorithm::Combinatorics to generate all the possible permutations and then simply looking any of those that didn't match the supplied list - and there was only one.
Plus Padovan primes
Task 2 concerns Padovan primes. We are given the definition of the Padovan series and asked to find the first 10 distinct members of the series that are prime. The complication is that the 10th exceeds the largest value that Perl can hold as an integer.
Generating the series is easy, and each successive number requires only the addition of two previous ones, so all that is needed for that is a simple extended add - ie a function that will add two arbitrarily long integers. I though of writing that myself, but then, why bother when Math::Bigint does the job.
However, what really makes Math::Bigint worth it is that Math::Prime::Util contains the function is_prime(), which works with big integers expressed in the same format as Math::Bigint - ie as a simple ASCII string of digits.
Postscript
So there are two boring solutions, probably unworthy of Mr Crain's erudition.
No comments:
Post a Comment