Skip to content

Add new practice exercise palindrome-products #758

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jiegillet
Copy link
Contributor

This is me procrastinating on working on exercism/elm-analyzer#96 because finding recursive functions in is hard :)

This one is potentially very hard, and I'm not sure of what the best approach is.
This exercise is about finding the largest/smallest product i * j that are also a palindromes for numbers i and j integer values within a certain range.
If you go at it naively (listing all possible pairs, finding the palindrome products and keeping the largest ones) two tests in particular will never pass because their range is 1000 to 9999, which is more than 80 million pairs (half if you only consider ordered pairs), which is simply too much for Elm to complete within the test runner time limit (of the order of 10 seconds I think).

If you take a smarter approach, such as generating pairs in descending/ascending order and stopping the search at the first palindrome product, then it's not problem, but it's a lot harder to code. For example, I wanted to use an algorithm requiring the use of a priority queue, so I had to build my own, which was difficult (although I love those kind of challenges).

In the Elixir track, we chose to mark those two test as "slow" and exclude them from the test runner, with this message to students. We could do something similar, although I don't like the approach so much, because to me, this exercise is about finding an efficient algorithm. I'm sure most students would try a simplest/brute force approach, see it pass, and move on, which to be honest is fine if our goal is to teach the Elm syntax.

I was leaning towards leaving all the tests in and adding a note saying that this exercise is about finding an efficient algorithm.

@ceddlyburge what's your take on this?

@ceddlyburge
Copy link
Contributor

I agree, the code does look tricky to implement !
Would the naive code create a stack overflow without tail call elimination? If so we could mention that and it could be a requirement of the solution, which would maybe address the slow tests issue?
Maybe adding an estimate if how long it takes to implement would be good too, so that students only stay it off they are happy to put in the time?

Copy link
Contributor

@ceddlyburge ceddlyburge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exercise looks good, so I've approved it, but we can still discuss the tests / requiring the code to be efficient

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