Your solution should return the largest and smallest palindromes, along with the factors of each within the range. If the largest or smallest palindrome has more than one pair of factors within the range, then return all the pairs.
Many language tracks do require the factors be returned. For example, see F# or Ruby.
The exercise descriptions are shared across languages - see problem-specifications. We don’t make track-specific edits.
Some tracks append to the shared instructions. For example, see Python. It might make sense to create an instructions.append.md for Rust. (I am not a Rust maintainer.)
That’s fair enough. I’m not sure an append would be appropriate, and it would be possible to change the exercise to require factors, but that might be a very breaking change.
I’m starting to see why this wasn’t changed before…
I’ll wait for the Rust maintainer, and see what they recommend. In the meantime please ignore the PR.
The exercise was added 6 years ago and the description was synced with problem-specifictions 4 years ago, so the discrepancy has existed for a while. I think two options make sense:
bring the exercise in line with the description (breaking change)
instructions.append.md to explain the discrepancy as mentioned above
The main downside of breaking an exercise is that the community solutions for that exercise are invalidated and won’t be shown to users anymore. @ellnix would you like to check the community solutions if there are any that are interesting? (Just the top results for relevant sorting mechanisms, the ones people are likely to see.) If there aren’t any particularly interesting solutions, we might as well do a breaking change I think.
They operate on ranges of the smallest (min * min) and largest (max * max) possible product and find the first and last numbers that are palindromes with multiples inside the range. It’s similar to looping through a 2D array without nested loops.
I’m not aware of a more creative solution to this exercise, I racked my brains for quite a bit today trying to see if I could get the test suite to complete in less than 10s (on my admittedly bad laptop) since I felt like I was missing something.
There are some features of interest in the conventional solutions:
This loop to determine if a number is a palindrome:
let mut reverse = 0;
let mut r = value;
while r > 0 {
reverse = reverse * 10 + r % 10;
r /= 10;
}
value == reverse
if i % 10 == 0 {
continue;
}
// ...
if j % 10 == 0 {
continue;
}
However, this doesn’t really change the big O profile of the solution.
Keeping track of min and max outside of the loop, preferably using Option, this means avoiding the allocation of every palindrome in a vector and also the linear search in an unsorted vector. The space complexity is good but it doesn’t do anything for the time complexity.
I’m not sure this would be a great idea, it doesn’t feel very professional.
More professional than just having incorrect instructions. Sometimes you gotta be pragmatic.
But I think we can do a breaking change here. The interesting solutions don’t do anything someone else isn’t gonna come up with for the new design.
I think published community solutions continue to appear even if they no longer pass the new tests.
Huh, that seems to be the case. I remember that solutions with failing tests would be hidden by default but there was a toggle to show them. I can’t find the toggle anymore and I can see failing solutions in the default view, so apparatly that got changed. Even more reason to do a breaking change.
@ellnix do you want to bring the exercise design in line with the instructions?
Sure, do you have any particular design considerations? It seems to be normal for returned collections in the Rust track to be Vecs, and I’m not sure they should be shoved inside the Palindrome struct since that would no longer conform to the newtype pattern (which this exercise seems to want to teach).
Perhaps a return type of Option<((Palindrome, Vec<u64>), (Palindrome, Vec<u64>))>? Looks a little bit silly.