Skip to main content
1 of 2
Neil
  • 184.4k
  • 12
  • 76
  • 290

Retina 0.8.2, 26 bytes

.+ $* (^(1)|(?<2>1\2)\1)+$ 

Try it online! Link includes test cases. Explanation: The first stage just converts to unary; the second stage adds successive triangular numbers to see if this will exactly consume the unary number. The ?<2> syntax reuses capturing group 2; the equivalent in Perl 5 would be something like this:

$_=(1x$_)=~/((?|^(1)|(1\2)\1))+$/ 

Try it online! Link is to test suite that outputs 0 or 1 for each line of input.

Neil
  • 184.4k
  • 12
  • 76
  • 290