[Question]
  [
A positive integer **x** is a square triangle number iff there are two different positive integers, **y** and **z**, which are smaller than **x** such that all of the sums
**x + y**
**x + z**
**y + z**
are perfect squares.
For example 30 is a square triangle number because
**30 + 6 = 62**
**30 + 19 = 72**
**6 + 19 = 52**
---
Your task is to write some code that takes a positive integer as input and determines whether or not it is a square triangle number. You should output one of two distinct values, one if the input is a square triangle number and the other otherwise.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so answers will be scored in bytes with fewer bytes being better.
## Testcases
Here are all of the square triangle numbers under 1000
```
30,44,47,48,60,66,69,70,78,86,90,92,94,95,96,98,108,113,116,118,120,122,124,125,126,132,138,142,147,150,152,154,156,157,158,159,160,165,170,176,180,182,185,186,188,190,192,194,195,196,197,198,200,207,212,214,216,218,221,222,224,227,230,232,234,236,237,238,239,240,246,248,253,258,260,264,266,267,268,270,273,274,275,276,278,280,281,282,283,284,285,286,290,296,298,302,303,306,308,310,312,314,317,318,320,322,323,324,326,328,329,330,331,332,333,334,335,336,338,340,344,347,350,351,352,356,357,360,362,364,368,370,371,372,374,376,377,378,380,382,384,385,386,387,388,389,390,392,394,396,402,405,408,410,413,414,415,418,420,422,423,424,426,429,430,432,434,435,436,438,440,442,443,444,445,446,447,448,449,452,456,458,462,464,466,467,468,470,472,476,477,479,480,482,484,485,488,490,491,492,494,496,497,498,500,501,502,503,504,505,506,507,508,509,510,512,515,516,518,522,523,524,527,528,530,533,536,538,540,542,543,546,548,549,550,551,552,554,557,558,560,562,563,564,566,568,569,570,571,572,573,574,575,576,578,579,582,585,588,590,592,593,594,598,600,602,603,604,605,606,608,610,612,613,614,615,616,618,620,621,623,624,626,627,628,630,632,633,634,636,638,639,640,641,642,643,644,645,646,650,652,656,657,658,659,660,662,666,667,668,670,672,674,677,678,680,682,683,686,687,689,690,692,694,695,696,698,700,701,702,704,706,707,708,709,710,711,712,713,714,715,716,717,718,719,720,722,723,726,728,730,734,737,739,740,742,744,745,746,750,752,755,756,758,760,762,764,765,767,768,770,772,773,774,776,778,779,780,782,783,784,785,786,788,789,790,791,792,793,794,795,796,797,798,800,802,803,804,805,810,812,814,816,817,818,819,820,822,825,826,827,828,829,830,832,833,834,836,837,838,840,842,846,847,848,849,850,851,852,854,855,856,858,860,861,862,863,864,866,867,868,869,870,871,872,873,874,875,876,877,878,879,880,882,884,888,890,891,893,896,897,898,902,903,904,905,908,912,913,914,915,916,918,920,923,924,926,927,928,929,931,932,933,935,936,938,940,941,942,944,946,947,948,950,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,968,970,972,974,976,978,980,981,984,986,987,988,992,993,995,996,998
```
[OEIS A242445](http://oeis.org/A242445)
  
[Answer]
# [Haskell](https://www.haskell.org/), 62 bytes
```
f x|l<-(^2)<$>[1..x]=or[b>x|c<-l,b<-l,a<-l,a-x+b-x==c,c<b,b<a]
```
[Try it online!](https://tio.run/##HY3LCoMwEEV/ZRAXkUykUSktJH5Bu@rSWkikxdL4QC2dhf@eGjeHwz2L25r583TO@xfQ6pRgjyxRcVnJNKVaD1NlS1obJRzaALNDELeCtG6wUXYLpvadefcaOjNegd0JRAnjd7kt06WHGOZ2@AEB5xCFEgXbN7a9JglU8og55gcsCpQZnk@1/wM "Haskell – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 bytes
```
R²_fṖŒcS€Æ²Ẹ
```
[Try it online!](https://tio.run/##AS0A0v9qZWxsef//UsKyX2bhuZbFkmNT4oKsw4bCsuG6uP8xMDAww4fDkGZq4oCdLP8 "Jelly – Try It Online")
### How it works
```
R²_fṖŒcS€Æ²Ẹ  Main link. Argument: x
R             Range; yield [1, 2, ..., x].
 ²            Square; yield [1², 2², ..., x²].
  _           Subtract; yield [1²-x, 2²-x, ..., x²-x].
    Ṗ         Pop; yield [1, 2, ..., x-1].
   f          Filter; keep those values of n²-x that lie between 1 and x-1.
              This list contains all integers n such that n+x is a perfect square.
              We'll try to find suitable values for y and z from this list.
     Œc       Yield all 2-combinations [y, z] of these integers.
       S€     Take the sum of each pair.
         Æ²   Test each resulting integer for squareness.
           Ẹ  Any; check is the resulting array contains a 1.
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~93~~ ~~87~~ 86 bytes
-1 byte thanks to Dennis
```
lambda n:{0}in[{m**.5%1for m in[x+y,n+x,n+y]}for x in range(1,n)for y in range(1+x,n)]
```
[Try it online!](https://tio.run/##TcoxCoQwEEDR3lNMIxiVJQo2AU@iFll2owNmlGCRIDn7mHQWv3n8M1zbQT2bceZd2@9PA6lbRqTptnX9GcrOHA4sJPBNaKnxqbDErD4pOE3rv@paEpnCi/IqFs6ML5ZSqALQgKlQqNMhXYDMDw "Python 2 – Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 19 bytes
```
~hṪ>₁ℕ₁ᵐ≜¬{⊇Ċ+¬~^₂}
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/vy7j4c5Vdo@aGh@1TAWSD7dOeNQ559Ca6kdd7Ue6tA@tqYt71NRU@/@/oaHZfwA "Brachylog – Try It Online")
Also 19 bytes: `~hṪ>₁ℕ₁ᵐ≜{⊇Ċ+}ᶠ~^₂ᵐ`
### Explanation
```
~hṪ                    Ṫ = [Input, A, B]
  Ṫ>₁                  Ṫ is strictly decreasing (i.e. Input > A > B)
  Ṫ  ℕ₁ᵐ               All members of Ṫ are in [1, +∞)
  Ṫ     ≜              Assign values to A and B that fit those constraints
  Ṫ      ¬{       }    It is impossible for Ṫ…
           ⊇Ċ            …that one of its 2-elements subset…
            Ċ+           …does not sum…
              ¬~^₂       …to a square
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 150 bytes
```
param($x)filter f($a,$b){($c=[math]::Sqrt($a+$b))-eq[math]::Floor($c)}1..($i=$x-1)|%{$y=$_;1..$i|%{$o+=+($y-ne$_)*(f $x $y)*(f $x $_)*(f $y $_)}};!!$o
```
[Try it online!](https://tio.run/##PcrRCoIwAIXhV5lwgi2bJN0pu@0FuoyQFRMH0@ka5DCffU2o7v7zcUb7Uu7ZKWNiHKWTPcXMWm28cqSlkAfc2ULxENde@u5WVZfJ@eR5csbV9OOzsdalH1vLoqDQAjMv2Xu3IAg0dULobdlc5BSBDwoN29OWYCYI//pa2Gpd6yyDjTGejh8 "PowerShell – Try It Online") or [Verify some test cases](https://tio.run/##PczRCoIwFAbge59iyQm21kRvlXXZC3QZIUsmCurmMnLYnn3NKO/@8/H/R6uXNI9Gdp2vn0M1tWpANQZxhDtZMFT82oupueX5ZTRTcBqcMDn@@dwpZUKPuGjb68VrYUSPYSageBplSYKh5TCzjLz3C1gOZREQ2vVSlFMMlg0SSnLANYIZgd3Sz@yanCt2O1DerS@zNA3zGErETihGFGH97fgP "PowerShell – Try It Online")
Takes input `$x`. Establishes a `filter` (here equivalent to a function) on two inputs `$a,$b`, which returns a Boolean true iff the `[math]::sqrt` of `$a+$b` is `-eq`ual to the `Floor` of that square root (i.e., it's an integer square root).
The rest of it is the meat of the program. We double-for loop up from `1` to `$x-1`. Each iteration, we check whether `$y` is `-n`ot`e`qual to `$_` (i.e., $z), and whether the function is true for all combinations of `$x`, `$y` and `$_`. If it is, `$o` is incremented by one (which makes it non-zero).
Finally, at the end, we double-Boolean-negate `$o`, which turns `0` into `False` and non-zero into `True`. That's left on the pipeline and output is implicit.
[Answer]
# [Haskell](https://www.haskell.org/), ~~75~~ 69 bytes
```
f x=or[all(`elem`map(^2)[1..x])[x+y,x+z,y+z]|y<-[1..x-1],z<-[1..y-1]]
```
[Try it online!](https://tio.run/##JYrBCoMwEER/ZY8JWcVUWyjol4QUc4hUutmK7SEJ/nsM7WGYx5t5us/LE5WyQJzeu3FEYvbkwxzcJh4XaXTbRitNVAmjyphUtkcam59vtMX851TZluBWnrZ95a8RjAuwPLjufYcwDAi32rqm1wjXe/2f "Haskell – Try It Online")
Could probably be improved if someone knows a shorter way to test if a number is square. I'm pretty sure using `sqrt` ends up being longer because `floor` turns the result into an integral type so you need to put `fromIntegral` in somewhere before you can compare to the original.
EDIT: Thanks @Wheat Wizard for taking off 6 bytes!
[Answer]
## JavaScript (ES7), ~~75~~ 71 bytes
```
f=
n=>(g=i=>i?--j?[n+i,i+j,j+n].some(e=>e**.5%1)?g(i):1:g(j=i-1):0)(j=n-1)
```
```
<input type=number min=1 oninput=o.textContent=f(+this.value)><pre id=o>
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 18 bytes
```
Lns-IL¨Ãæ2ù€OÅ²O0›
```
[Try it online!](https://tio.run/##ASgA1/8wNWFiMWX//0xucy1JTMKow4PDpjLDueKCrE/DhcKyTzDigLr//zE4 "05AB1E – Try It Online")
Thanks to [Emigna](https://codegolf.stackexchange.com/users/47066/emigna) for ~~-3~~ -1 byte ~~and a fix~~!
[Answer]
# [R](https://www.r-project.org/), 79 bytes
```
function(x){s=(1:x)^2
S=outer(y<-(z=s-x)[z>0&z<x],y,"+")
diag(S)=0
any(S%in%s)}
```
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/T6NCs7rYVsPQqkIzzogr2Da/tCS1SKPSRlejyrZYt0IzusrOQK3KpiJWp1JHSVtJkyslMzFdI1jT1oArMa9SI1g1M0@1WLP2f3FiQUFOJdAcExOdNM3/AA "R – Try It Online")
computes all the values of `y,z` with `y<-(z=s-x)[z>0&z<x]`, then computes all their sums with `outer(y,y,"+")`. This yields a square matrix where off-diagonal entries are potentially squares, as `y==z` only if they are on the diagonal. Hence, `diag(S)=0` sets the diagonals to zero, which are not perfect squares, and we test to see if `any` element of `S` is `%in%s`.
[Answer]
# [SWI-Prolog](http://www.swi-prolog.org/), 88 bytes
```
s(A,B,C):-between(A,B,C),C<B,between(1,B,X),B+C=:=X*X.
g(X):-s(1,X,Y),s(Y,X,Z),s(Y,Z,Y).
```
[Try it online!](https://tio.run/##ZY@xCoMwEIZ3n@K6JfUU7Sg6VAdd7OSQWjq0ECRQtJiADn13ezE6lIYM9/0/95G8x@E1dIGe1LJodsYcC54ET2kmKfuNsUhz3KOYIsEx94ssycRRhF7HBK1oagReOWp2paF1Q0tJuBipDbvdEQRdHnqOq09DUYVQP2YOSeABnQpSy7hCxyqOcHBQgtJU@xA7XiUNQukEm5WCWvW/Tgo26@66yNlYnW3@hLbcnd6mWDt6fYRwiiLuFqZRGcnsh5Yv)
```
s(A, B, C) :-
    between(A, B, C), % Find an integer C between A and B (inclusive),
    C < B,            % which is less than B.
    between(1, B, X), % Find an integer X between 1 and B (inclusive),
    B+C =:= X*X.      % of which (B+C) is the square.
g(X) :-
    s(1, X, Y), % Find Y: 1 <= Y < X, and X+Y is a perfect square
    s(Y, X, Z), % Find Z: Y <= Z < X, and X+Z is a perfect square
    s(Y, Z, Y). % Make sure that Z > Y and Y+Z is a perfect square
```
`g(X)` is the rule that takes an integer as parameter and outputs whether it is a square triangle number (true/false).
[Answer]
# JavaScript (ES7), 72 bytes
Returns `0` or `1`.
```
x=>(g=y=>z?y>z?![x+y,x+z,y+z].some(n=>n**.5%1)|g(y-1):g(x-1,z--):0)(z=x)
```
### Demo
```
let f=
x=>(g=y=>z?y>z?![x+y,x+z,y+z].some(n=>n**.5%1)|g(y-1):g(x-1,z--):0)(z=x)
for(n = 1; n < 150; n++) {
  f(n) && console.log(n)
}
```
[Answer]
# C, 113 bytes
```
p(n){return(int)sqrt(n)==sqrt(n);}f(x,y,z,r){for(r=y=0;++y<x;)for(z=y;++z<x;p(x+y)&p(x+z)&p(z+y)&&++r);return!r;}
```
Returns `0` if the number is square triangle, `1` otherwise.
[Try it online!](https://tio.run/##LU5BCoMwEDw3r4hCJUsixHPMT3oR2xRBU7taMBG/3nTTdi6zM7vsTF/f@z6lWXjY8ba@0IvBr7A8cSXL2v9gDic2FVRUCLt7oEAbrDZShnYzkI1oA8lIchabDFBlipliVpWUCOaXUKA5EqXwqRu8ALYzTqAnPGdzbxvDfdtorQ2X0sN3nTE4LgpHdYCdsp6R7p0oz9eLLxWnmuxI796N3X1J9Th9AA)
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 49 bytes
```
{∨/{0=+/(⍺=⍵),1|.5*⍨(⍺+⍵)(⍺+k)(⍵+k)}/¨,⍳2⍴1-⍨k←⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24TqRx0r9KsNbLX1NR717rJ91LtVU8ewRs9U61HvCpCINkgEzMgGUVuBVK3@oRU6j3o3Gz3q3WKoC1SXDTQHKFX7/79G2qEVQBlDAwNNfQgNAA "APL (Dyalog Unicode) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 bytes
```
ṖŒc;€ŒcS€Æ²ẠƊ€Ẹ
```
[Try it online!](https://tio.run/##y0rNyan8///hzmlHJyVbP2paA6SCgdThtkObHu5acKwLyH64a8f///8NzQA "Jelly – Try It Online")
### How?
```
ṖŒc;€ŒcS€Æ²ẠƊ€Ẹ || Full program.
                ||
Ṗ               || Popped range. Yields [1, N) ∩ ℤ.
 Œc             || Pairs (two-element combinations).
   ;€           || Append N to each.
            Ɗ€  || For each of the lists, check whether:
           Ạ    || ... All ...
       S€       || ... The sums of each of their...
     Œc         || ... Disjoint Pairs
         Æ²     || ... Are perfect squares.
              Ẹ || Test whether there is any value that satisfies the above.    
```
[Answer]
# [Clean](https://clean.cs.ru.nl), ~~95~~ ~~88~~ 86 bytes
```
import StdEnv
@x#l=[1..x-1]
=or[all(\n=or[i^2==n\\i<-l])[x+y,y+z,z+x]\\y<-l,z<-l|y<>z]
```
[Try it online!](https://tio.run/##FYyxCsMgFAD3fIXQpcUYYudYMqRDoVtGtSCJKcLTlMQWlX57bbIcxw03gFYu23l8g0ZWGZeNfc2LR70fr@5TtOEAjNOqCoTKgs0LVwBH4XYzjzNjTgjTEJAnHnAsI05lwkEKEbdYpg3f2FySzL1X25WhyYDXC2rRPqV1LfNvmEA910xu99xFp6wZ1j8 "Clean – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 73 bytes
```
->n{(1...n).any?{|b|(1...b).any?{|c|[n+b,b+c,n+c].all?{|r|r**0.5%1==0}}}}
```
[Try it online!](https://tio.run/##NYu7CoAwDAB/xUVQq6EKjtUPEQdTdCpBqoKl8dvjA7ztDs4fGGQxUnUUsxoAKIeJQh8Z@XP83fJACktUtiRlR5ice6pnXxQa2rQ2Rl8Psibv12idwza72e6RT16Gc7xEbg "Ruby – Try It Online")
[Answer]
# [Julia 0.6](http://julialang.org/), 61 bytes
Start reading from the function `all`. The first argument is an anonymous function checking that the square root of a number is an integer, this is applied to each value in the second argument. The single argument to `any` is a `Generator` with two for loops, which for each iteration contains the output of the `all` function. 
Thanks to Mr Xcoder for -2 bytes.
```
x->any(all(x->√x%1==0,[x+y,x+z,y+z])for y=1:x-1for z=1:y-1)
```
[Try it online!](https://tio.run/##yyrNyUw0@59mm5Sanpn3v0LXLjGvUiMxJ0cDyHzUMatC1dDW1kAnukK7UqdCu0qnUrsqVjMtv0ih0tbQqkLXEMSsAjIrdQ01/6fmpXA5FGfklyukaRgbaCLYhppcBUWZeSU5eRppmXkpGml6GkZWhgYGmpraQG0A "Julia 0.6 – Try It Online")
[Answer]
# [Pyt](https://github.com/mudkip201/pyt), 63 [bytes](https://github.com/mudkip201/pyt/wiki/Codepage)
```
0←Đ⁻Đ`⁻Đ3ȘĐ3Ș+√ĐƖ=4ȘĐ3ȘĐ3Ș+√ĐƖ=4ȘĐ3ȘĐ3Ș+√ĐƖ=4Ș6Ș**4Ș↔+↔łŕ⁻Đłŕŕŕ
```
Tests all possible combinations of y,z such that 1≤z<y<x
Returns 1 if x is a square triangle number, 0 otherwise
[Try it online!](https://tio.run/##K6gs@f/f4FHbhCMTHjXuPjIhAUwan5gBJrQfdcw6MuHYNFsTqACRomYnZmhpAelHbVO0gfho09GpYHNBDBD8/9/EBAA)
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~20~~ ~~19~~ 18 bytes
```
q:2XN!tG+wsvX^1\aA
```
[Try it online!](https://tio.run/##y00syfn/v9DKKMJPscRdu7y4LCLOMCbR8f9/YwMA "MATL – Try It Online") Returns 1 for falsey, 0 for truthy.
Testcases up to 500: [Try it online!](https://tio.run/##y00syflvamBgpeQQ4fG/0Moowk@xxEO7vLgsIs4wJtHxf529g8t/AA "MATL – Try It Online") (using `H` instead of `G`). Runtime is quadratic in the input size, so enumerating the testcases from `1` to `n` runs in `O(n^3)`, which is why enumerating all testcases up to 1000 times out on TIO.
* -1 byte and a conjecture less thanks to @LuisMendo
* -1 byte by a more clever check of integer-ness.
Removing `q` generates a sequence with the desired sequence as a subset, but without the constraint that `y` and `z` be strictly smaller than `x`. An example is `x=18`, `y=7`, `z=18`. 
```
q:    % Push 1...n-1
2XN   % Generate all permuations of choosing 2 numbers from the above.
!     % Transpose to take advantage of column-wise operators later on.
 G+   % Add n to these combinations, to have all combos of x+y and x+z
t  ws % Duplicate the combinations, swap to the top of the stack and sum to get y+z.
v     % Concatenate vertically. The array now contains columns of [x+y;x+z;y+z].
X^    % Element-wise square root of each element
1\    % Get remainder after division by 1.
a     % Check if any have remainders, columnwise. If so, it is not a square triangle.
A     % Check whether all combinations are not square triangle.
```
]