-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 exercise updated #1119
Conversation
Recursive solution, seems to be the fastest
Added a longest test case
More optimal, no ifs, faster :)
Some fine tuning....
Probably a minor enhancement
@nikamirrr I'm hesitant to add such a test on a whim. Currently this exercise is listed as a difficulty 6 in |
Will do, sure. Though, I would question the real difficulty. The most difficult part is the recursive mod-10 logic. Since you already have 10-digit problems among the tests, I don't think the one I add really increases complexity. But it will be very pedagogical stimulating the thought how one can more efficiently count the repeating letters. |
My point is that if the current solutions for 10-letter problems are acceptable, it does not take much to make them handle the test I add. All one need to do is to group the letters on each side. |
Allow me to suggest that you are almost correct; if However, consider if |
You do not need to count every letter individually. No matter how many letters you use, there are no more than 10 unique letters (unknowns) with 10 non-repeating options for each unknown 10N + O + 10N + O + 100T+10O+O == 1000L + 100A+10*T+E 20N + 13O + 90T - 1000L - 100*A - E == 0 So the complexity is O((10 + 1)!) |
Removed changes
Anyway, I am going to pull the test out of the PR and suggest a solution only. The test case will go through the JSON |
Ah, I see. I misunderstood you in grouping the letters; did not think of that. You are completely correct then. My apologies.
Corey McCandless
…On Nov 27, 2017, 13:09, at 13:09, Nikolay Mirin ***@***.***> wrote:
You do not need to count every letter individually. No matter how many
letters you use, there are no more than 10 unique letters (unknowns)
with 10 non-repeating options for each unknown
For example one can notice:
NO + NO + TOO == LATE
NO + NO + TOO - LATE == 0
10*N + O + 10*N + O + 100*T+10*O+O == 1000*L + 100*A+10*T+E
20*N + 13*O + 90*T - 1000*L - 100*A - E == 0
So the complexity is O((10 + 1)!)
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#1119 (comment)
|
A test case update suggested to complement this PR: exercism/python#1119
NP at all :) we are all having fun doing this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, some commenting would be nice, but perhaps not completely necessary for an example solution.
exercises/alphametics/example.py
Outdated
return dict(zip(t_lowdigs, t_digvals)) | ||
totchars = set() | ||
for p, chardict in enumerate(tchars): | ||
for c, cnt in tuple(chardict.items()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should run fine without wrapping chardict.items()
in tuple()
.
This is fine.
Let's keep it open till next week. I will add comments. :) @cmccandless with all my respect, I see why you propose running without chardict.items() in tuple(). If possible, please. check this behavior in python 3.6 on your side and let me know how chardict.items() works without tuple()
|
@nikamirrr My mistake; when I remarked on the |
NP, we have time, I will add comments over the weekend and update PR for the review. |
Added comments
Comments added |
A test case update suggested to complement this PR: exercism/python#1119
…#1024) A test case update suggested to complement this PR: exercism/python#1119
This issue has been automatically marked as |
Hello, would anybody pull this, please? |
@nikamirrr apologies, I was waiting for exercism/problem-specifications#1024 to be merged first, then I forgot about it. Merged. |
Let's cripple the brute force solutions. :)