▲ | nemoniac 6 days ago | |
The first code example on that page claims to solve "the 3SUM problem". According to [1], "the 3SUM problem asks if a given set of n real numbers contains three elements that sum to zero." It's not clear to me what problem the Janet code solves but it's clearly not that 3SUM problem. On the example input of
it outputs
For what it's worth, here's some Common Lisp code that does solve the 3SUM problem in O(n^2).
[1] https://en.wikipedia.org/wiki/3SUM | ||
▲ | bmacho 6 days ago | parent | next [-] | |
It outputs the indices corresponding to the solution. E.g.
| ||
▲ | lispitillo 6 days ago | parent | prev [-] | |
If you want a one line code, in J, for the 42 solutions:
Or the 8 solutions in a 2x12 matrix:
|