adamcrussell

Perl Weekly Challenge 023

Part 1

Sample Run

$ perl perl5/ch-1.pl 1 5 9 2 8 1 6
4, -7, 6, -7, 5

$ perl perl5/ch-1.pl 2 5 9 2 8 1 6
-11, 13, -13, 12

What I Did

My use of recursion here is pretty much for fun. Writing an outer loop that iterates for $order number of times would not look too weird here at all. Other than that note I think the code (should hopefully!) speak for itself.

Part 2

Sample Run

$ perl perl5/ch-2.pl 228
2, 2, 3, 19

$ perl perl5/ch-2.pl 1228
2, 2, 307

$ perl perl5/ch-2.pl 1000
2, 2, 2, 5, 5, 5

What I Did

Because of my method for implementing the anagram logic in Challenge 005 I pretty much had already written this code before. Check out that earlier challenge for a neat use of the Fundamental Theorem of Arithmetic which states that every integer greater than 1 is either a prime number itself or can be represented as the unique product of prime numbers.

Comments for this post were locked by the author