-
-
Notifications
You must be signed in to change notification settings - Fork 519
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
alphametics: Fast example solution? #849
Comments
From a Travis CI run:
|
I can say that https://travis-ci.org/petertseng/exercism-problem-specifications/builds/421220966 tells me that https://github.com/petertseng/exercism-problem-specifications/blob/verify/exercises/alphametics/verify.rb solves alphametics in 2.5 seconds on travis (the line Sorry I don't really have time to make a PR soon, so I don't object if someone else takes a better solution. I can describe my solution in words: I found that working from right-to-left was too slow and doesn't eliminate any possibilities at all. Every single digit is in the rightmost column, so even if you pre-assign 0 to its only possible digit, you will still examine all 9! permutations in the worst case, which is not acceptable for performance. Work left-to-right instead; the leftmost columns are sparsely populated. Working from right-to-left took 15 seconds on my computer, whereas working left-to-right took 1.9 seconds. |
Performance discussion in exercism/problem-specifications#1024 (comment) and all subsequent comments. Can cut the runtime down from 2.5 seconds (on Travis) to 0.5 seconds (on an unspecified computer, did not test myself) by stopping immediately when you find ONE solution rather than finding them all. Stopping at one solution is against the purpose of my code (this is verification code, it needs to make sure the solution is unique) therefore I cannot do it within the context of the problem-specifications repo. If you want that speedup you will have to do it yourself, or experiment with a port of exercism/python#1119 to see whether it does the claimed speedup. |
Great! thanks @petertseng |
I guess 53.421492s is not a reasonable amount of time. |
It's better than 582.287082s (although it will also depend on how much faster your machine is than the Travis CI machine) |
14.894647s, still an order of magnitude slower than @petertseng, on a Dell Inspiron 580 (about 2010 vintage?)
|
@n8chz If you want to make that a pull request to update https://github.com/exercism/ruby/blob/master/exercises/alphametics/.meta/solutions/alphametics.rb that would be great. |
Note that although #883 created https://github.com/exercism/ruby/blob/master/exercises/alphametics/.meta/solutions/alphametics_compact.rb, it's my belief that the Ruby track doesn't support multiple examples. This belief is rooted in the code https://github.com/exercism/ruby/blob/master/lib/tasks/exercise.rb#L26 . Therefore the https://github.com/exercism/ruby/blob/master/exercises/alphametics/.meta/solutions/alphametics.rb is still the solution that is being run in Travis CI. A person who wants to close this issue would want to rectify this. It cannot fairly be recommended that this issue be closed until then. |
Is this still slowing down the builds? (as it should according to @petertseng's comment above)??? |
According to the Travis logs for #964 a faster version of
Should this issue be closed? |
Everything I said is still true. There are two solutions, and the track doesn't support having two solutions, so it is not possible to predict which solution is being run. I will create a new issue for that. Since the track doesn't test the 10 letters case anymore because of #853, the fact that the solution remains slow is no longer visible. |
Thank you for the clarification 😁 |
Cool, well I don't have the permissions to close this issue, but maybe someone will do it. |
🙇 |
3 seconds is still slow. Edit: but not unreasonable :) |
Does anyone have a super-fast alphamentics solution?
We need an example solution that can solve this test:
ruby/exercises/alphametics/alphametics_test.rb
Line 76 in 83bf92a
TODO:
Update the example solution: https://github.com/exercism/ruby/blob/master/exercises/alphametics/.meta/solutions/alphametics.rb
With a faster one.
The text was updated successfully, but these errors were encountered: