Problem-specifications: pythagorean-triplet: improve readme and specification

Created on 24 Mar 2018  路  4Comments  路  Source: exercism/problem-specifications

@yawpitch submitted this over in https://github.com/exercism/exercism.io/issues/3743


I'm working on the Python track specifically, but I notice that across many of the language tracks the tests and examples do not reflect the description of the problem:

Pythagorean Triplet
A Pythagorean triplet is a set of three natural numbers, {a, b, c}, for which,
a**2 + b**2 = c**2
For example,
3**2 + 4**2 = 9 + 16 = 25 = 5**2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product a * b * c.

In the Python, Rust, and Haskell tracks, for instance, there are no tests whatsoever related to the "find the product a*b*c" statement, and all three require different constructs than what's implied by the problem description and title. The Javascript track, however, does require that the work produced can calculate the product.

Most helpful comment

Hey there, just editing the initial issue description to put backticks around the asterisks, otherwise something like a*b*c turns into abc and a**2 + b**2 = c**2 turns into a2 + b2 = c**2 which is not what we want to show in this issue (it would decrease understanding)

All 4 comments

Since we made different design choices than Project Euler and, as a result of the choices, we are not limited to validating a single numerical answer, I suggest we do away with finding the product. I suggest test suites simply check the values of a, b and c that a test case will ask for.

What test cases shall we recommend?

There are choices for how much parameterisation we want.

  • Only find the single triplet where a + b + c = 1000
  • Find triplets where a + b + c = N, for varying N
  • Find triplets where a + b + c < N, for varying N
  • Find triplets where a < N and b < N and c < N, for varying N
  • I"m sure one can find more options if you just look through http://exercism.io/contribute/canonical-data/pythagorean-triplet but I'm not going to do that.
  • Decide the problem is not a good fit for exercism and decide to deprecate it

"Only find the single triplet where a + b + c = 1000" is my least-preferred option. I do not see a need for me to express an ordering between any other options at this time.

Hey there, just editing the initial issue description to put backticks around the asterisks, otherwise something like a*b*c turns into abc and a**2 + b**2 = c**2 turns into a2 + b2 = c**2 which is not what we want to show in this issue (it would decrease understanding)

What test cases shall we recommend?

Checking the solution is much easier if we can ask to be given a, b and c. Therefore, I'd suggest changing the exercise to something like this:

_Create a function which receives the sum of the three sides, and returns one pythagorean triplet that satisfies the equation a + b + c = N._

Testing the answers should be straightforward:

  1. Check that a + b + c = N
  2. Check that a2 + b2 = c2

Edit: I misclicked enter and posted my comment uncompleted. Now it's okay ^^

Update on status of this issue: The canonical tests are created in https://github.com/exercism/problem-specifications/pull/1332.

A person who wants to close this issue should update https://github.com/exercism/problem-specifications/blob/master/exercises/pythagorean-triplet/description.md to match the new task (given N, find any pythagorean triplets whose sum is N).

Don't forget to use one of the words in https://help.github.com/articles/closing-issues-using-keywords/ in your commit message.

Was this page helpful?
0 / 5 - 0 ratings