Skip to main content
add tio link
Source Link

dc, 18 bytes

Try it online!

?8*1+dvd*[0]sI=Izp

Prints 1 if triangular, 0 if not.

Explanation:

?       get input (call it x)
8*1+    let y = 8 * x + 1
d       duplicate
vd*     square root, then square (dc's sqrt has integer precision)
[0]sI=I if y == sqrt(y)^2, leave 0 on stack, otherwise leave nothing
zp      print stack depth

dc, 18 bytes

?8*1+dvd*[0]sI=Izp

Prints 1 if triangular, 0 if not.

Explanation:

?       get input (call it x)
8*1+    let y = 8 * x + 1
d       duplicate
vd*     square root, then square (dc's sqrt has integer precision)
[0]sI=I if y == sqrt(y)^2, leave 0 on stack, otherwise leave nothing
zp      print stack depth

dc, 18 bytes

Try it online!

?8*1+dvd*[0]sI=Izp

Prints 1 if triangular, 0 if not.

Explanation:

?       get input (call it x)
8*1+    let y = 8 * x + 1
d       duplicate
vd*     square root, then square (dc's sqrt has integer precision)
[0]sI=I if y == sqrt(y)^2, leave 0 on stack, otherwise leave nothing
zp      print stack depth
Source Link

dc, 18 bytes

?8*1+dvd*[0]sI=Izp

Prints 1 if triangular, 0 if not.

Explanation:

?       get input (call it x)
8*1+    let y = 8 * x + 1
d       duplicate
vd*     square root, then square (dc's sqrt has integer precision)
[0]sI=I if y == sqrt(y)^2, leave 0 on stack, otherwise leave nothing
zp      print stack depth