| Bytes | Lang | Time | Link |
|---|---|---|---|
| 046 | Python 3.8 prerelease | 250102T004953Z | V_R |
| 025 | AWK | 250103T155934Z | wobtax |
| 022 | JavaScript V8 | 250102T145528Z | doubleun |
| 008 | Uiua | 250101T100856Z | lolad |
| 018 | Wolfram Language Mathematica | 250102T075543Z | Introduc |
| 026 | Google Sheets | 250101T165151Z | doubleun |
| 017 | x8664 machine code | 250102T135816Z | m90 |
| 013 | Charcoal | 250102T133031Z | Neil |
| 161 | TSQL setbased | 250101T191413Z | Razvan S |
| 023 | R | 250102T003907Z | Eonema |
| 031 | Ruby | 250101T205558Z | G B |
| 008 | Brachylog | 250101T180636Z | cjquines |
| 012 | APL+WIN | 250101T173900Z | Graham |
| 007 | Japt | 250101T120820Z | Shaggy |
| 045 | Retina 0.8.2 | 250101T100836Z | Neil |
Python 3.8 (pre-release), 46 47 48 bytes
-1 thanks to Neil
-1 thanks to ceilingcat
Takes quite a long time for inputs like 2**31-1...
f=lambda n:n*4in[(x*~x)**2for x in range(n+1)]
Explanation for original 48-byte version
f=lambda n:n in[(x*x+x)**2/4for x in range(n+1)]
The xth triangular number is (x*x+x)/2, and we're looking for the square of that: ((x*x+x)/2)**2
We can save two characters by squaring the numerator and denominator separately: (x*x+x)**2/4
We need range(n+1) instead of range(n) to return True when n is 1
AWK, 28 25 bytes
$0=(1+8*$0^.5)^.5%2==1{}1
Explanation: uses the formula in Eonema's answer. $0 is reassigned in the pattern, so it's printed automatically if it's 1; otherwise, we test for the pattern /0/ and print that.
Saved three bytes thanks to Marius_Couet.
Previous solution: 42 41 bytes
{for(b=0;$0>b;b+=a++**3);print($0~b);a=0}
Explanation:
- The empty for-loop repeatedly adds successive cubes
a^3tobuntilbis at least as large as the input line. - Print
1when$0is exactlyb, or0otherwise (the regex match works becauseb>=$0). - Reset
afor the next line.
JavaScript (V8), 22 bytes
n=>(8*n**.5+1)**.5%1>0
This is Arnauld's code with -1 by Shaggy, I'm just the messenger. Posting because of lack of a JavaScript answer.
Uiua, 9 8 bytes
∊\+⇡999√
-1 byte: Tbw - switched from checking \$n\in \sum k^3\$ to \$\sqrt{n}\in \sum k\$
Creates a list of \$\sum_{k=0}^n k \ (0\le n\le 999)\$, then checks membership of \$\sqrt{n}\$. Since the largest squared triangular number under \$2^{31}-1\$ is the 303rd, this range must be 3 digits so we go up to the 999th.
Wolfram Language (Mathematica), 18 bytes 21 bytes
OddQ@√(1+8√#)&
Edit
-3 thanks to att to shorten Sqrt
Google Sheets, 26 bytes 76 bytes
=0=mod(sqrt(1+8*A1^0.5),1)
Expects the integer in cell A1. Returns true or false.

x86-64 machine code, 17 bytes
31 C9 89 C8 F7 E1 F7 E1 FF C1 29 C7 77 F4 19 C0 C3
Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes a 32-bit integer in EDI and returns a 32-bit integer in EAX, which is 0 if the number is in the sequence and -1 if it is not.
In assembly:
f: xor ecx, ecx # Set ECX to 0.
r: mov eax, ecx # Set EAX to ECX.
mul ecx # Multiply EAX by ECX, producing the square.
mul ecx # Multiply EAX by ECX, producing the cube.
inc ecx # Add 1 to ECX.
sub edi, eax # Subtract the cube from the input number.
ja r # Jump back, to repeat, if it stays positive.
sbb eax, eax # Subtract EAX+CF from EAX, making it -CF.
# CF was set by the previous SUB instruction;
# it's 1 iff the value overflowed to negative.
ret # Return.
Charcoal, 13 bytes
№E⊕θX×ι⊕ι²×N⁴
Try it online! Link is to verbose version of code. Outputs a Charcoal boolean, i.e. - for a sum of cubes, nothing if not. Explanation: Port of my golf to @V_R's Python answer.
θ Input `n` as a string
⊕ Cast to integer and increment
E Map over implicit range
ι Current value
× Multiplied by
ι Current value
⊕ Incremented
X Raised to power
² Literal integer `2`
№ Contains
N Input `n` as a number
× Multiplied by
⁴ Literal integer `4`
Implicitly print
If potential floating-point accuracy is acceptable, then for 10 bytes:
⁼¹﹪₂⊕×⁸₂N²
Try it online! Link is to verbose version of code. Explanation: Port of @Eonema's R answer.
T-SQL (set-based), 161 bytes
DECLARE @ INT=9 SELECT COUNT(*) FROM (SELECT POWER(n*(n+1)/2,2)s FROM (SELECT TOP 999 ROW_NUMBER()OVER(ORDER BY(SELECT 1))n FROM master..spt_values)x)y WHERE s=@
T-SQL (iterative), 121 bytes
DECLARE @x INT=9DECLARE @ INT=1,@s INT=0 a:SET @s+=@*@*@ IF @s<@x AND @<303 BEGIN SET @+=1 GOTO a END PRINT 1-SIGN(@s^@x)
R, 23 bytes
\(x)(1+8*x^.5)^.5%%2==1
Explanation:
The nth square triangle number is \$x = (\frac{n(n+1)}{2})^2\$, so \$2\sqrt{x}=n^2+n\$, giving \$n=\frac{-1+\sqrt{1+8\sqrt{x}}}{2}\$. Since \$n\$ has to be an integer, that means \$\sqrt{1+8\sqrt{x}}\$ has to be an odd integer, i.e., \${\sqrt{1+8\sqrt{x}}}\mod{2}=1\$.
Brachylog, 8 bytes
≥ℕ⟦^₃ᵐ+?
Explanation
≥ℕ Get an integer in [0, input].
⟦ Get the range [0, that integer].
^₃ᵐ Map cube over that range.
+ Get its sum.
? Assert that sum equals the input.
Japt, 7 bytes
õ³å+ øU
õ³å+ øU :Implicit input of integer U
õ :Range [1,U]
³ :Cube each
å+ :Cumulative sums
øU :Contains U?
Retina 0.8.2, 45 bytes
.+
$*
((^1|1\2)+)(?<=(1)*1)(?<-3>\1)*$(?(3)^)
Try it online! Link includes some test cases. Explanation: Converts the input to unary, then searches for a triangular number whose square is the input.