Skip to main content
2 of 3
added the non-recursive version
Arnauld
  • 197.7k
  • 20
  • 179
  • 650

##JavaScript (ES6), 30 bytes

f=(n,k=1)=>!n||n>0&&f(n-k,k+1)

###Test cases

f=(n,k=1)=>!n||n>0&&f(n-k,k+1)

console.log(f(1))
console.log(f(3))
console.log(f(6))
console.log(f(10))
console.log(f(15))
console.log(f(21))
console.log(f(55))
console.log(f(276))
console.log(f(1540))
console.log(f(2701))
console.log(f(5050))
console.log(f(7626))
console.log(f(18915))
console.log(f(71253))
console.log(f(173166))
console.log(f(222111))
console.log(f(303031))
console.log(f(307720))
console.log(f(500500))
console.log(f(998991))

console.log(f(2))
console.log(f(4))
console.log(f(5))
console.log(f(7))
console.log(f(8))
console.log(f(9))
console.log(f(11))
console.log(f(16))
console.log(f(32))
console.log(f(50))
console.log(f(290))
console.log(f(555))
console.log(f(4576))
console.log(f(31988))
console.log(f(187394))
console.log(f(501500))
console.log(f(999999))

###Non-recursive version (ES7), 19 bytes

Port of Adnan's answer.

x=>(8*x+1)**.5%1==0
Arnauld
  • 197.7k
  • 20
  • 179
  • 650