Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 235 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Jelly, 4 bytes

R+\ċ

Try it online!

How?

R+\ċ - Main link: n
R - range(n) -> [1,2,3,...,N]
 \ - cumulative reduce by:
 + - addition -> [1,3,6,...,T(N)]
 ċ - count occurrences of right (n) in left -> 1 if triangular, 0 otherwise

Jelly, 4 bytes

R+\ċ

Try it online!

How?

R+\ċ - Main link: n
R - range(n) -> [1,2,3,...,N]
 \ - cumulative reduce by:
 + - addition -> [1,3,6,...,T(N)]
 ċ - count occurrences of right (n) in left -> 1 if triangular, 0 otherwise
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

AltStyle によって変換されたページ (->オリジナル) /