-
-
Notifications
You must be signed in to change notification settings - Fork 556
pythagorean-triplet: Add missing constraints to description #1365
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
Conversation
Added missing constraint to the Pythagorean triplet problem that is outlined in the linked Project Euler problem.
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.
Looks good! Thanks for contributing this, @TheBestJohn!
I have performed ad-hoc examination of canonical-data.json
which shows that all triplets in the canonical data correctly conform to this rule, so no updates should be required there:
Thu Oct 11 18:57:57 DST 2018
Python 3.7.0 (default, Aug 6 2018, 20:07:46)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> with open('canonical-data.json') as cd:
... data = json.load(cd)
...
>>> triplets = []
>>> for case in data['cases']:
... triplets.extend(case['expected'])
...
>>> for (a, b, c) in triplets:
... if a >= b or b >= c:
... print(f"malformed: ({a}, {b}, {c})")
...
>>>
I now plan to wait until Monday the 15th. This is to give other maintainers the chance to look at this and make comments and request changes if desired. If there are no objections, I plan to merge this on that date. I do not object if another maintainer wants to merge this before then. |
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.
Thanks for taking the time to improve this exercise @TheBestJohn. Also, thanks @coriolinus for the thorough review and look into the canonical data. 👍
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.
It is interesting because for the problem as currently stated in the description, finding the product a * b * c
, there is no need to impose an ordering between these three. However, for the problem posed in the canonical data, the ordering does matter. (the fact that the description and canonical data are not in agreement is noted in #1211 currently)
So, since we will eventually want this a < b < c
, there's no problem with having it now.
Ah yes I should have stated that I looked into the data and found no conflicts when submitting the pull request. also @rpottsoh no problem :) I just figured that it would definitely affect the performance of generated answers. Every result I bruteforce where As @petertseng says |
Added missing constraint to the Pythagorean triplet problem that is outlined in the linked Project Euler problem.