n-th term of the rise & reset sequence (Challenge taken from a multiplayer game (clash of code) at codingame.com)

The challenge

Find the n-th term of the following sequence: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4... or, to make it more obvious, {1}, {1,2}, {1,2,3}, {1,2,3,4}...

The sequence is made up from concatenated ranges from 1 to x, starting from 1, all the way up to infinity.

Rules / IO

Input and output can be in any format, as long as it's distinguishable. Input can be taken from any appropriate source: STDIN, file, etc...

The input can be 0- or 1-indexed, and the selected indexing must be mentioned in the post.

You will have to handle at least up to a result of 255 inclusive (meaning the 0-indexed maximum input is 32640). Anything over that has to be handled, if your language supports it.

This is code-golf so the shortest byte count wins!

Test cases (0-based indexing)

0 -&gt; 1
1 -&gt; 1
5 -&gt; 3
10 -&gt; 1
59 -&gt; 5
100 -&gt; 10
1001 -&gt; 12
Haskell, 27 26 bytes



([z|k&lt;-[1..],z&lt;-[1..k]]!!)


Try it online!

Thanks @DanD. for -1 byte!

This is an anonymous function, creating the infinite sequence an just returning the n-th element thereof: [[1..k]| k&lt;-[1..]] produces an infinite list of list: [[1],[1,2],[1,2,3],[1,2,3,4],...]. To concatenate these we can write [z|k&lt;-[1..],z&lt;-[1..k]] which results in [1,1,2,1,2,3,1,2,3,4,...] and finally (...!!) accepts the input n (pointless notation) and returns the n-th term (0-based).