Adding an exercise: pythagorean-triplet

Hi, I have been working on the pythagorean-triplet exercise, but in 8th. I’m not sure where coordination on this happens. I’ve got an initial commit in my fork, and just need to complete the example and tests.

Is this the best place to post an update and ask for feedback once I’m done? And I don’t want to step on anyone’s toes if they’re also working on it.



I would probably “just” open a PR on the 8th repo and ask for feedback there. That will allow for easy code commenting.

Great, I’ve done so now. It’s PR #96, if anyone would please re-open that and feel free to comment.


1 Like

In case anyone sees this, I’ve also started a thread on the 8th dev forum for this: Exercise: pythagorean-triplet . Probably it’s best to continue discussion there or on the PR itself. Thanks!

Hi, all! The exercise is live now, thanks to @axtens and @glennj’s support.

The example.8th version uses a clever algorithm to efficiently generate the pythagorean triplets. For my personal solution I submitted a more simple, brute force solution which I see in many of the C track entries. And it works, but it takes a few seconds to run; the first time I submitted, I got a timeout. The second submission was accepted (with the same code).

So … I’m just checking, is there cause for concern here? It’s flagged as Hard, and I think it’s achievable. But I’m slightly concerned that, assuming my code is relatively decent, a common solution is a bit too expensive.

Any obvious flaws in the above solution that would cause it to be slow? Or is it just to be expected relative to implementing the same algorithm in C, and it’s OK to push people to research a specialized solution (maybe in that case the instructions should link to an article about the mathematics?



I reckon including the link to the mathematics is worthwhile. I’m surprised you didn’t solve with the slv namespace (the Cassowary Constraint Solver), but I expect you’ll get to it eventually.

Regarding the “hardness”, I always found it hard to establish. What’s hard in COBOL is often easy in 8th. I don’t know if anything goes the other way, though.