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
We were given a comma separated list of number pairs, the pairs being separated by dashes, like 1000-1020. These were to be read as ranges of numbers like 1000, 1001, 1002, … , 1020.
The task is to sum up all the numbers which are composed of two identical halves. In this case, this would be just 1010.
The idea
In this case, a real idea isn’t needed. We just split the list of number pairs, which is given in a single line along the commas, then separate the pair, loop from the first number to the last and check whether the first half taken twice is the number as a whole. If so, we add the number to our sum.
So, this is the code:

The updated challenge
We now don’t only look at numbers made up of equal halves, but also at those made up of any number of repetitions, like 121212 (3 times 12) or 99999 (5 times 9).
The updated idea
For any given number with the length l we check, if the whole number is made up from sections with lengths from 1 to l/2.
Here is the code:


Leave a Reply