Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #393 (“Pythagoras Multiplied” and “Prime Step”)
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, with a new pair of tasks each Monday. You can find it here: The Weekly Challenge
The Weekly Challenge for the week of 2026-09-28 through 2026-10-04 is #393.
The tasks for challenge #393 are as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 393-1: Pythagoras Multiplied Submitted by: Ulrich Rieke You are given a positive integer n. Find the number of all positive integer triplets (a, b, c) so that a^2 + b^2 = c^2 and a, b and c are integers <= n.
I'll use a pair of nested ranged foreach loops to check all possible (c,a) pairs to see which (if any) need b values which are positive integers in order for "$a*$a + $b*$b == $c*$c" to be true.
Robbie Hatley's Perl Solution to The Weekly Challenge 393-1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 393-2: Prime Step Submitted by: Ulrich Rieke You are given a string with English alphabetic characters only. What is the absolute difference of the sum of the ASCII values of the characters in the string to the nearest prime number?
I only have two hours before the deadline, so I am NOT going to try to implement "nearest_prime" from scratch. Instead, I'll allow "prev_prime", "next_prime", and "is_prime" from CPAN module "Math::Prime::Util" to come to my aid.
Robbie Hatley's Perl Solution to The Weekly Challenge 393-2
That's it for challenge 393; see you on challenge 394!
Comments
Post a Comment