Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add palindrome-products exercise #157

Merged
merged 1 commit into from
Oct 19, 2024

Conversation

ageron
Copy link
Contributor

@ageron ageron commented Oct 15, 2024

This one was surprisingly tricky: getting the tests to pass was not that hard, but my solution was way too slow, it took almost a minute to run. Since Exercism rejects solutions that take more than ~20 seconds to run, I had to optimize my code. I managed to get it to run in less than a second, but unfortunately the code is now much less pleasant to read. In particular, the smallest and largest functions are very similar. I tried to factorize some things, but the code ended up being harder to read and understand, so it didn't really help, and I reverted to this version. I'm sure there must be a much better way to solve this exercise, but I didn't find it. Because of this, I set the difficulty to 6, even though getting the tests to pass initially isn't that hard. The difficulty is finding a clean and fast solution.

@isaacvando
Copy link
Contributor

Maybe this is the approach you already tried, but it looks like it wouldn't be too bad to extract a common function that accepts a comparison function, increment function, and bestValue that could then be used by largest and smallest.

Either way, looks good!

@ageron ageron merged commit eb5b841 into exercism:main Oct 19, 2024
4 checks passed
@ageron ageron deleted the add-palindrome-products branch October 19, 2024 05:05
@ageron
Copy link
Contributor Author

ageron commented Oct 19, 2024

Yes, that's what I tried, but it ended up making the code longer and less readable, unfortunately, probably because the functions differ in several little places. I chose to leave it as is, but if you manage to do better, I'd love to see it and we could update the solution. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants