Note: If you’re attempting to read this as a Fediverse post, you might find it rather confusing. I recommend using a web browser to read it properly, following this link.
The challenge
Today we were given a list of integer numbers, like 19874, 20001, 89089, …
The task was to pick out two digits of each number and combine them, preserving their order forming the largest possible 2-digit number and to add them all up. Here, this would be 98, 21, 99, …
The idea
Remember that you can’t use the number’s last digit for picking the result’s first. So, we pick the first occurrence of the largest digit, store it and then take the largest digit from its position position forward, combine the two, and we’re done.

The updated challenge
Do the same, but picking 12 digits instead of 2.
The updated idea
Basically the same as before, but 12 times.
The nice thing about Perl is that you can use integer arithmetics and string operations on the same data.


Leave a Reply