Recently, I created a binary word search that got me working with grids. It was fun, so I wanted to create some more similar content. Meet Pythagoras' Golfing grid:

Screenshot of the grid.

Each of d, e, f, g, h, i, j, k and T represent a numeric value.

Now consider an orthogonal triangle along the lower diagonal of this grid (so the vertical side is d, g, i; the horizontal base is i, j, k and; the hypotenuse is d, T, k).

We'll then assign some value constraints to various different cells/sums of cells, in a manner similar to Pythagoras' theorem:

  • Let \$a = d + g + i\$
  • Let \$b = i + j + k\$
  • Let \$c = f = dk\$
  • Let \$T = f - eh\$

You'll be given the value of \$T\$. You should then output the values of \$d,e,f,g,h,i,j,k\$, in that order, such that \$a^2 + b^2 = c^2\$ (equivalently, such that \$(d+g+i)^2 + (i+j+k)^2 = f^2 = (dk)^2\$) and such that \$T = f - eh\$

For example, given a value \$T = 55\$, the output should be:


as \$T = f-eh = 80-5\times5\$ and

$$\begin{align} (4+22+22)^2 + (22+22+20)^2 & = 48^2 + 64^2 \\ & = 2304 + 4096 = 6400 \\ & = 80^2 = (4\times20)^2 \end{align}$$

The resulting grid would look like this:

Screenshot of the resulting populated grid.


For clarity, your input will be a numeric value \$T\$:



For clarity, your output will be a comma delimited list of the values \$d,e,f,g,h,i,j,k\$:


Completion of Processing

There can be more than one answer for a given \$T\$, and as such, processing should complete upon discovery of the first valid set of values.

Loophole Prevention

Loopholes should not be utilized to achieve an answer. For example, returning hard coded values is prohibited.

Final Notes

While their is no official time limit, you can feel free to or not to add a variable cutoff time to your solution and return an answer of u (representing unsolvable) for the sake of brevity when reviewing answers. So long as this portion of your solution is clearly explained, it can be excluded from your size calculation.

If you choose to add a cutoff time, please make it an additional variable for input named c.


This is so the shortest code in bytes wins.

  • 1
    \$\begingroup\$ Since it may not have been clear enough before: I think you should make it clearer that there is more than one valid solution (if there is a solution), and that the values in the grid are positive integers. Your wording on the output also seems unnecessarily strict - why not just say "output the values \$ d,e,f,g,h,i,j,k \$"? \$\endgroup\$ Sep 20, 2021 at 18:23
  • \$\begingroup\$ Must the values be integers? \$\endgroup\$
    – att
    Sep 20, 2021 at 19:48
  • 3
    \$\begingroup\$ Then it seems like we can just return \$(d,e,f,g,h,i,j,k)=(1,1,5,0,5-t,2,-3,5)\$ (or similar hardcoded values) for any \$t\$. Example code. \$\endgroup\$
    – Arnauld
    Sep 20, 2021 at 20:58
  • 4
    \$\begingroup\$ I think this challenge should be moved to the sandbox so that it can be specified more accurately. Preventing hard-coded values is basically a non-observable requirement. Besides, with the current spec, we can just choose random values for \$a\$ and \$b\$ and still directly compute a matrix from them. \$\endgroup\$
    – Arnauld
    Sep 20, 2021 at 21:25
  • 2
    \$\begingroup\$ It was in the Sandbox \$\endgroup\$
    – W D
    Sep 20, 2021 at 22:42


Browse other questions tagged or ask your own question.