[Question]
  [
(Challenge taken from a multiplayer game (clash of code) at [codingame.com](https://www.codingame.com/home))
## 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 -> 1
1 -> 1
5 -> 3
10 -> 1
59 -> 5
100 -> 10
1001 -> 12
```
  
[Answer]
# [Haskell](https://www.haskell.org/), ~~27~~ 26 bytes
```
([z|k<-[1..],z<-[1..k]]!!)
```
[Try it online!](https://tio.run/nexus/haskell#@59mqxFdVZNtoxttqKcXq1MFYWTHxioqav7PTczMU7BV0CgoLQkuKfLJU1BRKM7ILwdSaQqmCpoKdnbY5HITC4Dy0QZ6epaxmgq6ugopmcUFOYmVxQolGakKpiUZCol5KWB2WmZRcYlCSWqeQlliTmlq8X8A "Haskell – TIO Nexus")
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<-[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<-[1..],z<-[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). 
[Answer]
# JavaScript, ~~29~~ 28 bytes
*-1 byte thanks to Arnauld!*
```
f=(n,m)=>n++<m?n:f(n+~m,-~m)
```
Uses the 0-indexed recursive formula found on OEIS.
When called with 1 argument as expected, the default value of the second, `m`, will be `undefined`. However, `-~undefined`, returns 1, which allows us to get the recursion rolling without an explicit `m = 1` in the argument list (thanks @Arnauld!)
Test snippet:
```
f=(n,m)=>n++<m?n:f(n+~m,-~m)
let examples = [0, 1, 5, 10, 15, 1000];
examples.forEach(function log(x) {
    console.log(x, " => ", f(x))
});
```
---
Alternatively, for the same byte count, we can have a curried function like so:
```
f=n=>m=>n++<m?n:f(n+~m)(-~m)
```
You can call this with `f(5)()` - it returns a function, which when called, returns the result, as described in [this meta post](http://meta.codegolf.stackexchange.com/a/11317/60919).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes, 1-indexed
```
RRF³ị
```
[Try it online!](https://tio.run/nexus/jelly#@x8U5HZo88Pd3f///zc0AAA "Jelly – TIO Nexus")
Explanation:
```
                                      (Assume N = 4 for the examples)
R      Generate a list of 1 to N      [1, 2, 3, 4]
 R     Generate new lists for each item on the previous list, with that item as N
                                      [[1], [1,2], ...]
  F    Flatten that list              [1, 1, 2, 1, 2, 3 ...]
   ³ị  Use the input number (³) as index (ị) on the list. 
       This is one-based:             [1, 1, 2, 1, 2, 3 ...] 
                                                ^
```
[Answer]
# Octave, 39 bytes
```
@(z)z-(n=ceil((8*z+1)^.5/2-.5))*(n-1)/2
```
1- based index
Explanation:
Consider this sequence:
```
1   1   2   1   2   3   1   2   3   4   1   2   3   4   5
```
if we count number of element of subsequences we have
```
1   2        3          4               5         
```
so using [Gauss formula for triangular number](https://en.wikipedia.org/wiki/Triangular_number)
we can form a formula for z:
```
z=n*(n+1)/2
```
that is a quadratic equation if we solve it for n we have
```
n=(sqrt(8*z+1)-1)/2
```
[Try It Online!](https://tio.run/#n0tRU)
[Answer]
## Haskell, ~~25~~ 24 bytes
```
(!!)$[1..]>>= \x->[1..x]
```
Usage example: `((!!)$[1..]>>= \x->[1..x]) 10` -> `1`. [Try it online!](https://tio.run/nexus/haskell#@59mq6GoqKkSbainF2tnZ6sQU6FrB@JUxP7PTczMU7BVKCjKzCtRUFFIUzA0@A8A "Haskell – TIO Nexus").
Maps the anonymous make-a-list-from-1-to-x function `\x->[1..x]` (the built-in `enumFromTo 1` is one byte longer) to the infinite list `[1..]` and concatenates the resulting lists into a single list. `!!` picks the nth element.
Thanks to @flawr for one byte.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
The program is 0-indexed, code:
```
ÌLL¹è
```
Explanation:
```
Ì       # Double increment the input
 LL     # List of list on the input
   ¹è   # Get nth element
```
Uses the **CP-1252** encoding. [Try it online!](https://tio.run/nexus/05ab1e#@3@4x8fn0M7DK/7/NwUA "05AB1E – TIO Nexus")
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 39 bytes
```
@(n){v=1:n,A=triu(v'+0*v),A(A>0)(n)}{3}
```
[Try it online!](https://tio.run/nexus/octave#@@@gkadZXWZraJWn42hbUpRZqlGmrm2gVaap46jhaGegCZSurTau/Z@YV6xhovkfAA "Octave – TIO Nexus")
This uses an alternative approach.
For e.g. `n=1` this `A=triu(v'+0*v)` creates the matrix 
```
1   1   1   1
0   2   2   2
0   0   3   3
0   0   0   4
```
When removing all the zero elements and appending the columns by `A(A>0)` we get the sequence:
```
1   1  2  1  2  3  1  2  3  4
```
Then it is just a matter of exctracting the `n`-th term of that sequence.
[Answer]
# [Python](https://docs.python.org/3/), ~~39~~ 36 bytes
*-3 bytes thanks to Dennis!*
A recursive lambda which uses 1-based indexing.
```
f=lambda n,m=1:n*(n<=m)or f(n-m,m+1)
```
[**Try it online!**](https://tio.run/nexus/python3#JYtBCsIwEEX3PcWnUJroBDoiLoLxIuIiJY0MmKlUF94@Rly9z@O/msMjljlFKJXAXndGz6HYdUM26gqVPdv63ETfpmc3x9eSIJqWj@jdo7ddbldpClcmHAgnArfFP04T33yHfz4OxwR3QcOIAUYoG7HW1i8)
We keep track of the current "rise" size using `m`. If `n` is smaller than or equal to `m`, it fits within the current "rise", and so we return it. However, if it's larger than `m`, we take `m` away from it, than add 1 to `m` and call the function recursively (moving on to the next rise).
[Answer]
## R, 25 bytes
```
i=scan();sequence(1:i)[i]
```
The index is 1-based.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), ~~6~~ 5 bytes
*1 byte saved thanks to [@TheBikingviking!](https://codegolf.stackexchange.com/users/55526/thebikingviking)*
```
@s._S
```
This uses 0-based indexing.
[Try it online!](http://pyth.herokuapp.com/?code=%40s._S&input=10&debug=0)
### Explanation
```
@          Index with implicit input into
   ._      all prefixes of
     S     1-based range of implicit input
 s         concatenated into an un-nested list
```
[Answer]
# Mathematica, ~~27~~ 24 bytes
Thanks @MartinEnder for 3 bytes!
```
((r=Range)@r@#<>1)[[#]]&
```
1-indexed. This throws errors that are safe to ignore.
**Explanation**
```
((r=Range)@r@#<>1)[[#]]&
  r=Range                 (* Store Range function in r *)
           r@#            (* Create list {1..n} *)
 (r      )@               (* For each element, generate {1..n} *)
              <>1         (* Join the lists and append a 1; throws errors *)
(                )[[#]]&  (* Take the nth element *)
```
[Answer]
# brainf\*ck, 78 bytes
```
,>+<[>[->>+>+<<<]>>>[-<<<+>>>]<<+[->->+<<]>[<<->>>[-<<+>>]<[-]]>[-]<<<+<-]>>+.
```
Takes input (0-based) and outputs as byte values. 
You can test it [here.](https://copy.sh/brainfuck/?c=LD4rPFs-Wy0-Pis-Kzw8PF0-Pj5bLTw8PCs-Pj5dPDwrWy0-LT4rPDxdPls8PC0-Pj5bLTw8Kz4-XTxbLV1dPlstXTw8PCs8LV0-Pisu) 
Input requires a `\` before decimal numbers (e.g. `\10` for 10). If the output is a printable ASCII character, you should see it. Otherwise, hit view memory -> final dump. The value that was printed is in the 3rd cell (cell number 2).
**Explanation:**
Cell 0 (INPUT): is the input and is decremented my 1 each time through the loop.
Cell 1 (RESET): increments by 1 every time it is equal to TERM. To do this, every time through the loop we add 1 and if they are not equal we subtract 1.
Cell 2 (TERM): increments by 1 every loop and is set to 0 if it matches RESET. To do this, I only copy the value back from HOLD if this cell was not equal to RESET.
Cell 3 (EQUAL): is used to check if RESET and TERM are equal.
Cell 4 (HOLD): is used to copy the values of RESET and TERM back after the equals check.
```
,>+<              # get input and put a 1 in RESET
[                 # for INPUT to 0
  >[->>+>+<<<]    # copy RESET to EQUAL and HOLD
  >>>[-<<<+>>>]   # copy HOLD back into RESET
  <<+             # add 1 to TERM
  [->->+<<]       # subtract TERM from EQUAL and copy it to HOLD
  >[              # if RESET and TERM were not equal
    <<-           # subtract 1 from RESET
    >>>[-<<+>>]   # copy HOLD back to TERM
    <[-]          # zero out EQUAL
  ]               # end if
  >[-]            # zero out HOLD
  <<<+            # add 1 to RESET (this cancels out the subtraction if
                  #     RESET did not equal TERM)
  <-              # subtract 1 from INPUT
]>>+.             # end for and add 1 because the sequence resets to 1 not 0
```
[Answer]
## Pyke, 6 bytes
```
OmSsQ@
```
[Try it here!](http://pyke.catbus.co.uk/?code=OmSsQ%40&input=0)
```
O      -    input+2
 mS    -   map(range(1,i+1), range(^))
   s   -  sum(^)
    Q@ - ^[input]
```
0-indexed.
[Answer]
## R, 43 41 bytes
Edit: Found a shorter recursive approach by using [A002262](https://oeis.org/A002262) + 1 (0 indexed):
```
f=function(n,m=1)`if`(n<m,n+1,f(n-m,m+1))
```
Old version:
```
n=scan();n-choose(floor((1+sqrt(8*n))/2),2)
```
1-indexed formula from OEIS.
[Answer]
# [Perl 6](http://perl6.org/), 21 bytes
```
{map(|^*,^∞)[$_]+1}
```
0-indexed. [Try it online!](https://tio.run/nexus/perl6#Ky1OVSgz00u25uLKrVRQS1Ow/V@dm1igUROnpRP3qGOeZrRKfKy2Ye3/4sRKhTQFA2suCMMQxjCFixhY/wcA "Perl 6 – TIO Nexus")
### How it works:
```
{                 }  # A lambda.
         ^∞          # Range from 0 to Inf-1. (Same byte count as 0..*, but cooler.)
 map( ^*,  )         # Map each number n to the range 0..(n-1),
     |               # And slip each range into the outer list.
            [$_]     # Index the sequence with the lambda argument.
                +1   # Add 1.
```
---
# [Perl 6](http://perl6.org/), 21 bytes
```
{[\,](1..*).flat[$_]}
```
0-indexed. [Try it online!](https://tio.run/nexus/perl6#Ky1OVSgz00u25uLKrVRQS1Ow/V8dHaMTq2Gop6elqZeWk1gSrRIfW/u/OLFSIU3BwJoLwjCEMUzhIgbW/wE "Perl 6 – TIO Nexus")
### How it works:
```
{                   }  # A lambda.
      1..*             # Range from 1 to infinity.
 [ ,](    )            # Fold it with the comma operator,
  \                    # and return all intermediate results, e.g. (1), (1,2), (1,2,3)...
           .flat       # Flatten the sequence.
                [$_]   # Index it with the lambda argument.
```
[Answer]
Neither of these solutions is as short as [JungHawn Min's](https://codegolf.stackexchange.com/a/107692/56178), but they're alternate approaches, which is something I guess. Both are unnamed functions taking a (1-indexed) positive integer input and returning a positive integer.
# Mathematica, 30 bytes
```
-#^2-#&@⌈√(2#)-3/2⌉/2+#&
```
An actual mathematical formula for this function! Made more readable (in part by translating the 3-byte characters `⌈`, `√`, and `⌉`):
```
# - ((#^2 + #) / 2 &)[Ceiling[Sqrt[2 * #] - 3/2]] &
```
`Ceiling[Sqrt[2 * #] - 1/2]` tells us which sublist the input refers to, from which we subtract one to tell us which sublist ends before we get to the input; then `((#^2 + #) / 2 &)` computes how many elements occur in all the sublists before the one we care about, which we subtract from the input `#` to get our answer. (Some will notice the familiar formula `(#^2 + #) / 2` for the `#`th triangular number; `Ceiling[Sqrt[2 * #] - 1/2]` is essentially the inverse function.)
# Mathematica, 32 bytes
```
If[#2<=#,#2,#0[#+1,#2-#]]&[1,#]&
```
Recursive solution, basically the same as in [Billywob's answer](https://codegolf.stackexchange.com/a/107678/56178) and others.
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 46 bytes
Zero indexed
```
(<>()){(({}())[()]){({}[()])<>}{}}<>([{}()]{})
```
[Try it online!](https://tio.run/nexus/brain-flak#@69hY6ehqVmtoVFdC6SjNTRjgZzqWjDDxq62urYWqCAaJBlbXav5/78lAA "Brain-Flak – TIO Nexus")
### Stack Clean, 48 bytes
```
(<>()){(({}())[()]){({}[()])<>}{}}{}<>([{}()]{})
```
[Try it online!](https://tio.run/nexus/brain-flak#@69hY6ehqVmtoVFdC6SjNTRjgZzqWjDDxq62uhaIgEqiQdKx1bWa//9bAgA "Brain-Flak – TIO Nexus")
## Explanation
This is a modified version of the [modulo function](https://github.com/DJMcMayhem/Brain-Flak/wiki/Basic-Arithmetic-Operations#modulo-positive-only). Instead of using a constant number as the divisor it increments the divisor for each time the divisor is subtracted from it (once per outside loop iteration).
### Annotated Code
```
(<>())       # Switch to the opposite stack and push 1 (the initial divisor)
{            # (outside loop) While top of stack is not 0...
  (          # Push...
    ({}())   # Push the divisor plus 1
  [()])      # ...minus one (ie push a copy of the original divisor
  {          # (inner loop) While the top of stack does not equal zero
    ({}[()]) # Decrement the top of the active stack
    <>       # Switch stacks
  }{}        # (inside loop) End loop and pop zero off the top of stack)
}            # (outside loop) End loop
<>           # Switch stacks (to the one with the divisor)
([{}()]{})   # Calculate the result
```
[Answer]
# Java 8, ~~85~~ ~~73~~ 55 bytes
```
n->f(n,1)+1int f(int n,int m){return n<m?n:f(n-m,m+1);}
```
0-indexed recursive approach with the formula provided in the [OEIS](https://oeis.org/A002260):
> 
> `a(n) = 1 + A002262(n)`.  
> 
> [*A002262*](https://oeis.org/A002262): `a(n)=f(n,1)` with `f(n,m) = if n<m then n else f(n-m,m+1)`.
> 
> 
> 
[Try it here.](https://tio.run/##jY6xboMwEIZ3nuIfbQVIGDK0tM0ThCVj1cFxTOMUnxEcqaKIZ6c26U4k@6w7/ff5u6irynxr6HL6mXSj@h57ZemeAJbYdLXSBlVs5wG0iJVkGSZjuOFUILxjouyjFpQWclUkZUiv16g8o1Udw9fgs8HxxibTfiBOIqV@sNJYnbx3hoeOQG9uR68BlbnUrQpZjhPQDsfGavSsODxXb09wQVMcuLP0/fkFJR@OUR4u@JD5nRsxqwKHW8/G5X7gvA073JBwOeVabORSolhMbJcZy99sX56gbJ7J/AuPyTj9AQ)
---
**Old answer (~~85~~ 56 bytes):**
```
n->{int m=~-(int)Math.sqrt(8*n+1)/2;return n-m*-~m/2+1;}
```
Used the other 0-indexed formula provided in the [OEIS](https://oeis.org/A002260):
> 
> n-th term is `n - m*(m+1)/2 + 1`, where `m = floor((sqrt(8*n+1) - 1) / 2)`.
> 
> 
> 
[Try it here.](https://tio.run/##hU7BCsIwDL3vK3Jslc5NEJShf@AuHsVDrVWrazbbTBCZvz479SqFJJD3Xl7eRd6lqBuNl8O1V5X0HtbS4DMBMEjaHaXSUA7rBwDFhom8CEgXOpQnSUZBCQhL6FGsnoPELl9i0PK1pHPqb47YfITjnE@mhdPUOgQUdiRedjId50XXF0nwatp9Fbx@lvfaHMCGOGxDzuBpuwPJv1k2D0/apnVLaRMoqpBhqljGP8n@8nmEn8XuYw9mi6hDFlf8YnZJ178B)
[Answer]
# MATL, 8 bytes
```
:"@:]vG)
```
This solution uses 1-based indexing
Try it at [**MATL Online**](https://matl.io/?code=%3A%22%40%3A%5DvG%29&inputs=6&version=19.7.2)
**Explanation**
```
        Implicitly grab input (N)
:       Create an array from [1...N]
"       For each element (A) in this array...
  @:    Create an array from [1....A]
]       End for loop
v       Vertically concatenate everything on the stack
G       Explicitly grab the input again
)       And use it to index into the vertically concatenated array
        Implicitly display the result
```
[Answer]
# [Perl](https://www.perl.org/), 30 bytes
29 bytes of code + `-p` flag.
```
map{$\-=$c++if$c<++$\}0..$_}{
```
[Try it online!](https://tio.run/nexus/perl#U1YsSC3KUdAt@J@bWFCtEqNrq5KsrZ2ZppJso62tElNroKenEl9b/f@/KQA "Perl – TIO Nexus")
[Answer]
## [QBIC](https://drive.google.com/drive/folders/0B0R1Jgqp8Gg4cVJCZkRkdEthZDQ), 21 bytes, 1-indexed
```
:[a|[b|~q=a|_Xc\q=q+1
```
Explanation:
```
:      Get 'a' from the cmd line
[a|    FOR (b = 1; b <= a; b++) This creates an outer loop from 1 to N
[b|    FOR (c = 1; c <= b; c++) This creates an iteration, yielding the 1, 12, 123 pattern
       'q' stores how many terms we've seen. It starts at 1 b default.
~q=a   if we are at the desired term (q == a)
|_Xc   Then quit, and print 'c' (the current number in the sequence)
\q=q+1 Else, increase 'q' and run again.
```
Slightly more interesting approach, but 10 bytes longer:
```
:{~b+q>=a|_xa-b|\b=b+q┘q=q+1
```
This program continuously calculates the total number of numbers in this bracket and all previous ones (`1 at loop 1, 3 at loop 2, 6 at loop 3 ...`). When that counter exceeds the sought-after index N, then return X from the current bracket, where X is N minus the previous amount of the counter.
[Answer]
## Ruby, 30 bytes
```
->n{(0..n).find{|x|0>=n-=x}+n}
```
1-based indexing
[Answer]
# R, 37 bytes
```
n=scan();for(i in 2:n)T=c(T,1:i);T[n]
```
Takes input from `n`, and creates the sequence for the first `n` sequences. This makes it somewhat inefficient at higher inputs, but it should be fine. It then returns the `n`-th entry, 1-indexed.
Uses a nice little trick by starting off the sequence with `T`, which is `TRUE` or `1` by default.
[Answer]
# C11, 48 bytes
```
int f(int x){int q=1;while(x>q)x-=q++;return x;}
```
[Try it online!](https://tio.run/nexus/c-gcc#@6@cmZecU5qSqmBTXJKSma@XYcfFlZlXopCmASIrNKtBVKGtoXV5RmZOqkaFXaFmha5toba2dVFqSWlRnkKFdS1ER25iZp6GZjUXJ1ijNRdncXJiXpqGkmqKko5ahSZQoKAIKAUVSdOo0ASK1f7/b2hgCAA)
Also works in C++ and Java.
---
An alternative for the same byte count:
```
int f(int x){int q=0;while(x>++q)x-=q;return x;}
```
[Answer]
# brainfuck, 141 bytes
I know I'm too late for the bounty, but I just wanted to see how many bytes the algorithm I thought of would end up being.
This program is zero-indexed.
```
,>+<[[->>+>+<<<]>>[-<<+>>]<[->+>>+<<<]>[-<+>]>>+[[-<->>+<]>[-<+>]<<<<]>>[>>>]>[.[<<<]]<<<<<<<[[-]>>>[-<+<<+>>>]<[->+<]<<<<<]>>>[>>>]<<<]>[.>]
```
[**Try it online**](https://copy.sh/brainfuck/?c=LD4rPFtbLT4-Kz4rPDw8XT4-Wy08PCs-Pl08Wy0-Kz4-Kzw8PF0-Wy08Kz5dPj4rW1stPC0-Pis8XT5bLTwrPl08PDw8XT4-Wz4-Pl0-Wy4KWzw8PF1dPDw8PDw8PFtbLV0-Pj5bLTwrPDwrPj4-XTxbLT4rPF08PDw8PF0-Pj5bPj4-XTw8PF0-Wy4-XQ$$)
* Select **Dynamic (infinite) Memory**, or it won't work
* To test input values > `255`, change **Cell size (Bits)** to **16** or **32**.
* The interpreter explains how to give input. For **decimal input** use `\5` for input of `5`.
	+ The maximum decimal value you can test input with is `\999`
	+ Hex input can go as high the cell-size.
---
### Explanation:
This shows the program broken up by step, showing what happens for input of `5`. `#` are placed in the ideal memory dump locations for the interpreter. 
You will probably want to use checkbox **Dump Memory at char: `#`** if running this version. This will dump the memory upon hitting `#`, allowing you to see the value on the tape in the event that it's an unprintable character, or to see what happens at any step you want. The cell that the pointer is on will be in bold.
```
,>+<                       (5) 1
[[->>+>+<<<]>>[-<<+>>]       5 1 (0) 5
<[->+>>+<<<]>[-<+>]>>+       5 1 0 5 (2)
[[-<->>+<]>[-<+>]<<<<] (0) 0 4 1 0 3 2 0 0
>>[>>>]                      4 1 0 3 2 0 (0) 0
                             1 1 0 (0) 2 0
>[.#[<<<]]<<<<                4 1 0 (3) 2 0 0 0
<<<[[-]>>>[-<+<<+>>>]<[->+<]<<<<<]>>> (3) 1 0 3 2 0 0 0
[>>>]<<<]>[.#>]
Tape structure:
    (cell_1 cell_2 temp), (cell_1 cell_2 temp), ...
Take Input;
If not zero:
  copy last pair to the right and add one to its cell_2
  subtract each cell_2 from each cell_1 (leaving each cell_2 intact)
  move checking from left to right: 
    If cell_1 is zero and cell_2 isn't:
      print cell_2
    Else:
      copy last cell_1 back, overwriting each previous cell_1
Else:
  right one and print result
```
[**Try it online**](https://copy.sh/brainfuck/?c=LD4rPCAgICAgICAgICAgICAgICAgICAgICAgKDUpIDEKW1stPj4rPis8PDxdPj5bLTw8Kz4-XSAgICAgICA1IDEgKDApIDUKPFstPis-Pis8PDxdPlstPCs-XT4-KyAgICAgICA1IDEgMCA1ICgyKQpbWy08LT4-KzxdPlstPCs-XTw8PDxdICgwKSAwIDQgMSAwIDMgMiAwIDAKPj5bPj4-XSAgICAgICAgICAgICAgICAgICAgICA0IDEgMCAzIDIgMCAoMCkgMAogICAgICAgICAgICAgICAgICAgICAgICAgICAgIDEgMSAwICgwKSAyIDAKPlsuI1s8PDxdXTw8PDwgICAgICAgICAgICAgICAgNCAxIDAgKDMpIDIgMCAwIDAKPDw8W1stXT4-PlstPCs8PCs-Pj5dPFstPis8XTw8PDw8XT4-PiAoMykgMSAwIDMgMiAwIDAgMApbPj4-XTw8PF0-Wy4jPl0KClRhcGUgc3RydWN0dXJlOgogICAgKGNlbGxfMSBjZWxsXzIgdGVtcCksIChjZWxsXzEgY2VsbF8yIHRlbXApLCAuLi4KClRha2UgSW5wdXQ7CklmIG5vdCB6ZXJvOgogIGNvcHkgbGFzdCBwYWlyIHRvIHRoZSByaWdodCBhbmQgYWRkIG9uZSB0byBpdHMgY2VsbF8yCiAgc3VidHJhY3QgZWFjaCBjZWxsXzIgZnJvbSBlYWNoIGNlbGxfMSAobGVhdmluZyBlYWNoIGNlbGxfMiBpbnRhY3QpCiAgbW92ZSBjaGVja2luZyBmcm9tIGxlZnQgdG8gcmlnaHQ6IAogICAgSWYgY2VsbF8xIGlzIHplcm8gYW5kIGNlbGxfMiBpc24ndDoKICAgICAgcHJpbnQgY2VsbF8yCiAgICBFbHNlOgogICAgICBjb3B5IGxhc3QgY2VsbF8xIGJhY2ssIG92ZXJ3cml0aW5nIGVhY2ggcHJldmlvdXMgY2VsbF8xCkVsc2U6CiAgcmlnaHQgb25lIGFuZCBwcmludCByZXN1bHQ$) 
* Select **Dynamic (infinite) Memory**, or it won't work
* **Dump Memory at char: `#`**
---
Notes:
* To run this on another interpreter that doesn't allow moving to the left of the starting cell (that's why I use Dynamic Memory), put in a bunch of `>` at the start. The number required may vary depending on the input value, but is O(1).
[Answer]
# [tinylisp](https://github.com/dloscutoff/Esolangs/tree/master/tinylisp) (repl), 90 bytes (0-indexed)
```
(d r(q((n j x)(i n(i(e j x)(r(s n 1)1(s x(s 0 1)))(r(s n 1)(s j(s 0 1))x))j
(q((n)(r n 1 1
```
Or, non-competing (using a feature that was committed after this challenge was posted), **80 bytes**:
```
(d r(q((n j x)(i n(i(e j x)(r(s n 1)1(a x 1))(r(s n 1)(a j 1)x))j
(q((n)(r n 1 1
```
The first line defines a helper function `r`, and the second line is an unnamed function that takes `n` and returns the nth term of the sequence. I've specified this as a repl submission because the repl autocompletes parentheses at the end of every line, not just at the end of the program. With those caveats, here's a version modified to work at [Try it online](https://tio.run/nexus/tinylisp#RYwxDoAwDAN3XuHR3po/wdAMlShLfh9CEWKIHNsnJ3dMnuSAI8SOwc7jNZMXBkxWGnWtfv1xiX9pSF6dNq6xgh5k8bDWTJk3), and here's an [ungolfed version](https://tio.run/nexus/tinylisp#hY/BCoMwEETvfsUck0OhCp77KWVt1hKIsY3m0K@Pm0YhQqE5bYY3M0xSbiYDZ4dA4aObRhkecQ924UvghdcGUI6mwZBccns85uhXDuKZ7KqLakcofkdyN3hci4iD3H819CPji1TFUEscOolrNVooMqYruAj/HYU/akQoTfntG2tfGSjj9DlQonJbtkz0OlkC@Sej77VOaQM) run against inputs 0 through 54.
### Explanation
I'll use the noncompeting version here. The only difference is that the official version has to implement addition as two subtractions.
```
(d r           Define r to be:
 (q(           A lambda function (= a list of two elements, quoted to prevent evaluation):
  (n j x)       Arguments n, j (the range counter), and x (the range limit)
  (i n          If n is truthy, i.e. nonzero:
   (i(e j x)     If counter equals limit:
    (r            Call r recursively on:
     (s n 1)       n-1
     1             counter reset to 1
     (a x 1))      limit increased by 1
    (r           Else, call r recursively on:
     (s n 1)       n-1
     (a j 1)       counter increased by 1
     x))           same limit
   j))))        Else, we're done; return the counter value
(q(            Lambda function:
 (n)            Argument n
 (r n 1 1)))    Call r with n, counter = 1, range limit = 1
```
[Answer]
# C, 54 bytes
Not the shortest C solution, but it has the merit of running in constant time (no loops, just math). It uses zero-based indexing:
```
x;f(n){x=floor(sqrt(8*n+1)-1)/2;return 1+n-x*(x+1)/2;}
```
Ungolfed:
```
int f(int n) {
    int x = floor(sqrt(8*n+1)-1)/2; //calculate the number of the current subsequence (zero based)
    return 1+n-x*(x+1)/2;   //x*(x+1)/2 is the zero based index of the `1` starting the subsequence
}
```
Test with:
```
#include <math.h>
#include <assert.h>
#include <stdio.h>
x;f(n){x=floor(sqrt(8*n+1)-1)/2;return 1+n-x*(x+1)/2;}
int main(){
    int i;
    for(i = 0; i < 10; i++) printf("%d ", f(i));
    printf("\n");
    assert(f(0) == 1);
    assert(f(1) == 1);
    assert(f(5) == 3);
    assert(f(10) == 1);
    assert(f(59) == 5);
    assert(f(100) == 10);
    assert(f(1001) == 12);
}
```
[Answer]
# C, 103 bytes
For a begginer it's okay, I think :).
```
int main(){int n,c,i,j;scanf("%d",&n);while(c<n){for(i=1;i<=j;i++){c++;if(c==n)printf("%d",i);}j++;}}
```
or the formatted way
```
#include <stdio.h>
int main() {
    int n,c,i,j;
    scanf("%d",&n);
    while(c<n) 
    {
        for(i=1;i<=j;i++)
        {
            c++;
            if(c==n) printf("%d",i);
        }
        j++;
    }
}
```
[Answer]
# [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 21 bytes, 0-based indexing
```
?d8*1+v1-2/d1+*2/-1+p
```
[Try the dc program online!](https://tio.run/nexus/dc#@2@fYqFlqF1mqGukn2KorWWkr2uoXfD/v6GBgSEA "dc – TIO Nexus") 
Explanation:
```
?      Push input number n.
d      Duplicate n at the top of the stack.
8*1+   Replace n at the top of the stack with 8n+1.
v      Replace 8n+1 at the top of the stack with the floor of its square root.
1-2/   Subtract 1, and divide by 2 (ignoring any fractional part).
```
The top of the stack now holds the index k of the greatest triangular number that is <= n.
```
d1+*2/ Compute k(k+1)/2, which is the greatest triangular number <= n.
-      Subtract n-(the greatest triangular number <= n). The first n is on the stack in position 2, because the input number n was duplicated at the top of the stack at the very beginning of the program, and only one of the values was popped and used (until now).
1+     Add 1 because the desired sequence starts over again at 1 (not 0) at every triangular number.
p      Print the answer.
```
This dc program can be converted into a competitively-sized bash script:
# [Bash](https://www.gnu.org/software/bash/) + Unix utilities, 28 bytes, 0-based indexing
```
dc -e"?d8*1+v1-2/d1+*2/-1+p"
```
[Try the bash program online!](https://tio.run/nexus/bash#@5@SrKCbqmSfYqFlqF1mqGukn2KorWWkr2uoXaD0/7@hgYHhfwA "Bash – TIO Nexus")
[Answer]
# C, ~~81~~ 44 bytes
straight iterative method, 0 indexed, and with some gentle massaging;
```
m=1,c=1;f(n){for(;n--;c=c^m?c+1:!!++m);c=c;}
```
[Try it online!](https://tio.run/nexus/c-gcc#FcixCoAgEADQva@4hOAOE3JoqEP6kyAsocErpCbp263e@Ep0tvXOckChHI6ELMawd36Ok9d2rGutI/3BT9nlgrjsggS5AoAzfRNQNatqA/YDEf@dtutOAh1XT@mHFw "C (gcc) – TIO Nexus")
]