exercism / scala

Exercism exercises in Scala.
https://exercism.org/tracks/scala
MIT License
123 stars 131 forks source link

Pythagorean Triplet in the Scala is broken? #636

Closed dam4rus closed 2 years ago

dam4rus commented 4 years ago

I don't know if I report this to the right place but I've seem to have found a task in the Scala track which is just plain wrong. So here's the readme:

A Pythagorean triplet is a set of three natural numbers, {a, b, c}, for which,

a**2 + b**2 = c**2
and such that,

a < b < c
For example,

3**2 + 4**2 = 9 + 16 = 25 = 5**2.
Given an input integer N, find all Pythagorean triplets for which a + b + c = N.

For example, with N = 1000, there is exactly one Pythagorean triplet for which a + b + c = 1000: {200, 375, 425}.

It states that we need to find all the triplets that's true for the following formula: a+b+c=N where N is the input parameter. Now, the Scala track is set up so that it passes two parameters: start, end.

test("pythagoreanTriplets 1 to 10") {
  PythagoreanTriplet.pythagoreanTriplets(1, 10) should be (Seq((3, 4, 5), (6, 8, 10)))
}

This doesn't make any sense to me and contradicts the readme. What is this range exactly? It's definitely not the sum of the triplet since the first sum of the triplets are 12 (3+4+5).

Also the expected values don't make any sense to me.

test("isPythagorean") {
  ..
  PythagoreanTriplet.isPythagorean((3, 5, 4)) should be (true)
  ..
}

How is that a Pythagorean triplet when a triplet is required to conform to the following rule: a < b < c? Also 3 2 + 5 2 <> 4 ** 2. I've completed this task in the F# track which is correctly set up. It passes a single argument N and the expected values are as it should be. I've also checked out the Rust track and the test cases matches F#'s. Maybe I'm getting something wrong here but this seems like a bug to me.

LarsWestergren commented 2 years ago

Agreed, the instructions are confusing, and the tests seem to have assumptions that no other language track has - instead of rejecting a triplet like (5,4,3) the tests seems to expect the implementer to sort the incoming parameters in ascending order first.