[Question]
  [
It is fairly simple to, given a number `n`, create a range from `0` to `n-1`. In fact, many languages provide this operation as a builtin.
The following CJam program reads an integer, and then prints out such a range ([Try it online!](https://tio.run/##S85KzP3/vyhT5/9/QwMDAA "CJam – Try It Online")):
```
ri,
```
Notice that it prints out numbers *without* a separator.
## The Challenge
Your task is to reverse this process. You should write a program that, given a string representing a range, returns the number used to produce that range.
## Specifications
* The numbers are given without any separator.
* You may assume the string forms a valid range.
* You may use 0- or 1-based indexing for your range.
* You may assume that a correct output will never exceed 32,767 (so a valid input will never have a length greater than 152,725).
* You may assume that a correct output will always be positive (so you do not have to handle 0 or negative).
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest competing answer (measured in bytes) wins.
## Test Cases
0-indexed:
```
0123 -> 4
0 -> 1
0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 -> 101
```
1-indexed:
```
1234 -> 4
1 -> 1
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 -> 100
```
  
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), ~~91~~ 80 bytes
0-indexed.
```
X*L:-atom_length(X,L),
     between(0,L,Y),
     numlist(0,Y,B),
     atomic_list_concat(B,X)
     ;L=0.
```
Newlines added for readability.
[Try it online!](https://tio.run/##FcpBCoAgEEDR46QyhdWuaNPaA9hKTMQE08iJjm@5/I9/3Skk1@bXlyKZmFqN6VTBRocHkSAo7BZfayPhIGCjEJ8z@Ix/brBSqLs3qpIyKRqNZAVJZ7HwrpSG98PYMNl9 "Prolog (SWI) – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 5 bytes
```
LCmLN
```
[Try it online!](https://tio.run/##DY6xbQNADMR28QSSTnc61WkNz2HAcBVk/s/3BMn33@/nnOfP9/k65zyy0NR4MzKzEtnJVE46t6KyqlBdLNWUaxFIFIAGIQyM7ejsanQ3Wz3tXgaTRbBJikNzFUqVoBYljaydmJwaTA9HM@NZh9NluE3LY3s39g7tje0V7YX2PsfjHw "Husk – Try It Online")
Only letters!
Takes input as a string, result is 1-indexed.
### Explanation
```
LCmLN
  mLN    get the list of lengths of all positive naturals
 C       cut the input into slices of those lengths
L        get the length of the resulting list
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~7~~ 6 bytes
1-indexed.
```
āηJsk>
```
[Try it online!](https://tio.run/##MzBNTDJM/f//SOO57V7F2Xb//yuBAQA "05AB1E – Try It Online")
or as a [Test Suite](https://tio.run/##HY4tbsJxEEQ9pyBoxM7uzH5UcABu0SaoyiYkJJieqhJBda/07y@YpyZvnun9A5ftfr1t99/vv5/z1@dpux2ej7f983E4bjvs4MEXlNUDA@AIEEKi0Bg3h7uH0@Xp5e0TFgiPCIYio6JjaASdQVJMFpsjE@QKUVKq1Jq0RHpGMpWZlZ1TViivKJYqq6pr2hrtHc1WZ1d3z9isoFlns0SzRrOa7R8)
**Explanation**
```
ā        # push range [1 ... len(input)]
 η       # compute prefixes of the range
  J      # join each prefix to a string
   sk    # get index of the input in the list of prefixes
     >   # increment
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~9~~ 7 bytes
```
⟦kṫᵐc,Ẹ
```
[Try it online!](https://tio.run/##ASUA2v9icmFjaHlsb2cy///in6Zr4bmr4bWQYyzhurj//1r/IjAxMjMi "Brachylog – Try It Online")
0-indexed.
### Explanation
Here we pass the input through the Output variable, and access the result through the Input variable.
```
⟦          The result is the input to a range…
 k         …with the last element removed…
  ṫᵐ       …which when all elements are casted to string…
    c      …and are then concatenated results in the input string
     ,Ẹ    (Append the empty string, this is necessary for it to work in the case where the 
             input is the empty string)
```
[Answer]
# Java 8, ~~66~~ 59 bytes
```
s->{int r=0;for(String c="";!c.equals(s);c+=r++);return r;}
```
0-indexed
-7 bytes thanks to *@PunPun1000*.
~~I have the feeling this can be shortened by only checking the length of the input somehow, since we can assume the input is always valid. Still figuring this out.~~ Unable to figure this out, and it will probably cost too many bytes in Java to be useful anyway (same applies to returning a substring of the end of a 1-indexed input).
**Explanation:**
[Try it here.](https://tio.run/##hZDPTsJAEIfvPMXKCUIgO/9n0@Ab6MWj8VBLMVUs2BYTY3h2XBGukuwcdua333zZ1/KznG93dfu6ejtWm7Lvw13ZtN@jEJp2qLt1WdXh/vd6aoRq8jB0TfsS@mmRm4dc@fRDOTRVuA9tWIZjP7/9/s12y1ist93lRbUcj4ubalF/7MtNP8mAarbsZrNp0dXDvmtDVxyOxR9wt3/eZOCZ@7ltVuE9a51Rj0@hnP45PXz1Q/2@2O6HxS6Phk07aRfVZBwBaTw9Of4Tupq4jsh7WNQ8QQQABAIGAQUDh4QRAREJGQUVDR0TRQJCImISUjJyShwZGJmYWVjZ2DlJFBAUEhYRFROXpFFBUUlZRVVNXZNFA0MjYxNTM3NLHh0cnZxdXN3cPaWYslDKy1IGpRxK2fnyBYfR4fgD)
```
s->{                 // Method with String parameter and integer return-type
  int r=0;           //  Result-integer
  for(String c="";   //  Check-String
      !c.equals(s);  //  Loop as long as the sum-String doesn't equal the input-String
    c+=r++           //   Append the number to the the Check-String,
                     //   and increase the Result-integer by 1
  );                 //  End of loop
  return r;          //  Return the result-integer
}                    // End of method
```
[Answer]
# [Ly](https://github.com/LyricLy/Ly), 29 bytes
```
iys&p>0<11[ppl>s1+<lfspSylL]>
```
[Try it online!](https://tio.run/##BcE9CgIxEAbQ29jYzPczkwRkT2BnKbaCkCKw1Z4@vjevvX/XeVtHPID3WvM4cX/M77le13x@jr0DlLNaHwgAhGAkCg0dg0GQFM1ksbFzKARRkpUqNXUNh2FattPl5u6RkUim0plZ2bLnqCgUS@U/ "Ly – Try It Online")
Can't believe this worked as well as it did...
[Answer]
# [Japt](https://github.com/ETHproductions/japt/), 8 bytes
Starting to get to grips with function methods in Japt.
0-indexed. Can take input as a string, an integer or an array containing 0 or 1 elements.
```
_o ¬¥U}a
```
[Test it](https://ethproductions.github.io/japt/?v=1.4.5&code=X28grKVVfWE=&input=IjAxMjM0NTY3ODkxMDExMTIxMzE0MTUxNjE3MTgxOTIwMjEyMjIzMjQyNTI2MjcyODI5MzAzMTMyMzMzNDM1MzYzNzM4Mzk0MDQxNDI0MzQ0NDU0NjQ3NDg0OTUwNTE1MjUzNTQ1NTU2NTc1ODU5NjA2MTYyNjM2NDY1NjY2NzY4Njk3MDcxNzI3Mzc0NzU3Njc3Nzg3OTgwODE4MjgzODQ4NTg2ODc4ODg5OTA5MTkyOTM5NDk1OTY5Nzk4OTkxMDAi)
---
## Explanation
Implicit input of string `U`.
```
_     }a
```
Get the first integer `>=0` that returns true when passed through a function that ...
```
o
```
Generates an array of integers from `0` to 1 less than the current integer ...
```
¬
```
Joins it to a string ...
```
¥U
```
Checks that string for equality with `U`.
Implicit output of resulting integer.
---
## Alternative, 8 bytes
```
ÊÇo ¬ÃbU
```
[Test it](https://ethproductions.github.io/japt/?v=1.4.5&code=ysdvIKzDYlU=&input=IjAxMjM0NTY3ODkxMDExMTIxMzE0MTUxNjE3MTgxOTIwMjEyMjIzMjQyNTI2MjcyODI5MzAzMTMyMzMzNDM1MzYzNzM4Mzk0MDQxNDI0MzQ0NDU0NjQ3NDg0OTUwNTE1MjUzNTQ1NTU2NTc1ODU5NjA2MTYyNjM2NDY1NjY2NzY4Njk3MDcxNzI3Mzc0NzU3Njc3Nzg3OTgwODE4MjgzODQ4NTg2ODc4ODg5OTA5MTkyOTM5NDk1OTY5Nzk4OTkxMDAi)
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 13 bytes
```
Ｉ⌕Ｅ⁺ψθ⪫ＥκＩλωθ
```
[Try it online!](https://tio.run/##HY67asNAFER/ReUuyHDfD1wGUgQM/gXhFBERcmw5Mf76zdrNFIdh5py@puvpPC2tHa/zeitv03Yr7/P6WQ7TTzkuv1t5jMOljsPHeV5f8HscXq2ldnp/xqXWum8NkFjUPBIBEQkZBRUNHQOTgJCImISUjJyCkoGRiZmFlY2dg1NAUEhYRFRMXEJSQVFJWUVVTV1D08DQyNjE1MzcwtLB0cnZxdXN3cMzIDAoOCQ0LDwiMiG7UPaz7EPZS9mdoe3@2m5b/gE "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
          λ     Inner map variable (μ inner map index also works)
         Ｉ      Cast to string
        κ       Outer map index
       Ｅ        Map over implicit range
      ⪫    ω    Join result
     θ          Input string
   ⁺ψ           Plus an extra character
  Ｅ             Map over each character
 ⌕          θ   Find the index of the original string
Ｉ               Cast from integer to string
                Implicit print
```
[Answer]
# Haskell, ~~40~~ 37 bytes
```
f s=[n|n<-[0..],(show=<<[0..n])>s]!!0
```
Function that reverses zero-based ranges.
Thanks to Laikoni for saving 3 bytes!
[Try it online.](https://tio.run/##y0gszk7Nyfn/P02h2DY6rybPRjfaQE8vVkejOCO/3NbGBsTLi9W0K45VVDT4n5uYmadgq5CSz6UABAVFmXklCioKaQpKBkoYIoZYhIyMTbCLmpqZW1gaGhgaGhoZGitx/QcA)
[Answer]
# [Retina](https://github.com/m-ender/retina), 30 bytes
```
+1`(\d+?)(?!\D)(?<!\1.+)
$0;
;
```
Recursively adds a semicolon after each number then counts the number of semicolons
[Try it online!](https://tio.run/##DY4xakNRDAR738KQwuZD0GolrYQDbnKMX9iQFGlShNz/@zVTLbPz9/3/8/s8jg2Py/613a@X@3n/XPw473jfrqc3u51ux2FwRpZ6YAAcRCBREBrj5nB3enh6ubx9aASdZDBZFJsTFggPRkRGhaJj0hLpyYzMrFR2TlmhvFhRWVWqrpEJclGhVElqTVujvdnR2dXq7hmbFTTrbJZo1mhWs70A "Retina – Try It Online")
[Answer]
# JavaScript (ES6), ~~32~~ 31 bytes
*Saved 1 byte thanks to Challenger5*
```
f=(s,r=n='')=>r<s?f(s,r+n++):+n
```
### Test cases
```
f=(s,r=n='')=>r<s?f(s,r+n++):+n
console.log(f('0123'))
console.log(f('0'))
console.log(f(''))
console.log(f('0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100'))
```
[Answer]
## [Perl 5](https://www.perl.org/), 19 bytes
**18 bytes code + 1 for `-p`.**
```
$i++while s/$i\B//
```
Uses 1-based indexing. -7 bytes thanks to @[nwellnhof](https://codegolf.stackexchange.com/users/9296/nwellnhof)'s *much* better approach!
[Try it online!](https://tio.run/##DY47agNREASv4kCZMDuf7pmeVOdwKvCCsBbL4Nt7/fKiqo7794Pnedmv19/P/XF/e22X/eO2befpkWC1xs3dw9Ph9PJ2@YSFR0QGglHRoZi09IzMRDIrO5UDgyOQAIhCQxgancEkSBab4pSVV1QWilXVpZq29o7ORrOru9UjkyuUgqhSS5qxWUOzYrNEs6BZz/b3PH7259frfD/@AQ "Perl 5 – Try It Online")
### Explanation
`$\` is a special variable that is `print`ed automatically after each statement, so by using that to store our number we don't need to update `$_` (which is automatically printed as part of the functionality of the `-p` flag) to contain the desired output. Then, whilst the input starts with `$\`, remove it and `redo` the program, which again increments `$\` and replaces it. When it no longer finds the number at the beginning of the string, we're done! Finally, decrement `$\` so we have the last number in the range.
[Answer]
# Mathematica, 46 bytes
```
Array[""<>ToString/@Range@#&,2^15]~Position~#&
```
1-indexed
**input**
> 
> ["12345678910"]
> 
> 
> 
[Answer]
# [Ruby](http://ruby-doc.org/), ~~51~~ ~~50~~ 46 bytes
```
->n{(0..4e4).map{|x|(1..x).to_a.join}.index n}
```
(This is my first Ruby program ever so it must be easy to golf it further)
-4 bytes thanks to @Nnnes
[Answer]
# [Python 2](https://docs.python.org/2/), 43 bytes
```
f=lambda s,i=1,r='':r<s and-~f(s,i+1,r+`i`)
```
[Try it online!](https://tio.run/##ZY09bsMwDIXn6hTaLEJqEMXNUKO6RFbDQJTEdhjYlCGpQ5Ze3RVdZOoD@PcBfG955nugw7oObvLz5eZlMuisia6qmviVpKfb@8@gCtWF6jOeYcV5CTHL9Eyi1C71OfbX75gw0IQzZlXvi0CML09qqmr3CEgq5agQhhAlSiQZPY29soa0BRDi5F7AsoFuefBuO91@Fm18Ixuyh/rj2IklImXpp0m17D@oUREAOMcXgeQ44rhTV0L@hdd7aMTbnwka/kYAw339BQ "Python 2 – Try It Online")
---
# [Python 2](https://docs.python.org/2/), 43 bytes
```
f=lambda s,i=1:s>''and-~f(s[len(`i`):],i+1)
```
[Try it online!](https://tio.run/##ZY1NasMwEIXX1Sm0swarIYrbRQ3qIbI1hqiN7UyRR0ZSF9nk6o7GIas8mL8H873lmi@BDus6Wu/mn7OTSaM1bfquKkfn99uoUucHUic8QdtrrA2sOC8hZpmuSZTapSHH4fc/Jgzkccasmn0RiOnJpLaqdn8BSaUcFcIYokSJJKOjaVBGU8GCEEf7NAwD6o4H76avu6@izd@czTKH5uOzF0tEytJ5rzrmj2pSBADW8kUgOY447tiXkJfwZg@teHtAUPM3Amju6x0 "Python 2 – Try It Online")
---
# [Python](https://docs.python.org/2/), 46 bytes
```
lambda s:s[-sum(i*'0'in s for i in range(5)):]
```
[Try it online!](https://tio.run/##ZU7BroIwEDzbr@iNrvAMFTk8kv6EV@SACrgGtqRbD349trznRSfZ3ckkM7Pz098s7ZfenJaxnc7XVnLF9Q8/JoXbJE@QJMveOokyUNfS0KkSoGoWnGbrvOQnizA77rzrLg/HaGnECb0q8gAQg/kPpipJdneLpNg7hfCRqjNKNYAQR/MWdAxI63gi101a/was@qqskt4Xh7IRs0Pysh1HVfdqUARgTCwiWP@n2HRsQv5Xb5FDJTZ/fsyiGQGyuJcX "Python 2 – Try It Online")
A different strategy. Takes a number of characters from the end equal to the length of the largest run of `0`'s in s.
---
# [Python](https://docs.python.org/2/), 46 bytes
```
f=lambda s,c=0:c*'0'in s and f(s,c+1)or s[-c:]
```
[Try it online!](https://tio.run/##PY1BDoIwEADP9hV7oxU0FPUgST/BlXCoCLgGtqStB1@PLYqbNG0n2Zn57R@GimXp1ain212Dy1qVl@0@yRMkcKDpDj0PNJXCWHD1oS2bBafZWA/u7Vg4R9d527Uv69DQiBN6fsrDCDZsWiqT5Pg0SNx5y1H0wYUQClbT0HGZUfALxiq1ARkFaR2v@JZNWl/DrHwlK5LF6Xxp2GyRPOhx5HXPB05CKBVDJCCWKJaqJvj/vy1T5KJku@8@Zb/l5QM "Python 2 – Try It Online")
Recursive version of the above.
[Answer]
# [R](https://www.r-project.org/), 47 bytes
```
n=nchar(scan(,""));which(cumsum(nchar(1:n))==n)
```
[Try it online!](https://tio.run/##K/r/P882LzkjsUijODkxT0NHSUlT07o8IzM5QyO5NLe4NFcDImtolaepaWubp/nf0MjYxNTM3MLS0MDQ0NDoPwA "R – Try It Online")
1-indexed
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), ~~17~~ 11 bytes
-6 bytes thanks to [ngn](https://codegolf.stackexchange.com/users/24908/ngn).
```
{,\⍕¨⍳≢⍵}⍳⊂
```
[Try it online!](https://tio.run/##HU4/SsNhFNu9yG9p4eW9vH93cSmUuhR0FXFxEBR@4OIFnLqXXsCjfBdpP11CQkKS3dNxu3/eHR8frtfDeP962dyP9fv3NNbz@PgZ6@X1j32@TXeBGpe7w2bBxH/lkdUQAAoD4QgkCq2iUFVTqmtoammbGEzNjOYWllbWFIJKI@kMJovt4nB1c7p7eHp5hwRCw4LhEZFR0SmJ1LRkekZmVnZJobSsWF5RWVXd0vNQz7GeRT1DPT/LcgM "APL (Dyalog Unicode) – Try It Online")
`⍳⊂` find the **ɩ**ndex of the entire argument in
`{`…`}` the result of this anonymous function:
 `≢` length of the argument
 `⍳` **ɩ**ntegers until that
 `⍕¨` format (stringify) each
 `,\` cumulative concatenation of those
[Answer]
# [Python 2](https://docs.python.org/2/), 46 bytes
0-indexed
```
l=lambda x,z="",y=0:z<x and l(x,z+`y`,y+1)or y
```
[Try it online!](https://tio.run/##1Y89bsJgEET7nMJygy1c7Oz/RvFdcESRSA4gRIG5vPmukXY0mvfmtj1@rhfe93Vel7/v89I9p9fc99M20@fr69ktl3O3Di08nrbTtB0xXu/dtt/uv5fHsA49gUXNIwsEgCFQGByBRDExmFlY2dg5OLmEBMIiomLiEpJSSgplFVU1dQ1NLSODsYmpmbmFpZWTw9nF1c3dw9MrKBAcEhoWHhEZlZRITklNS8/IzCqqJlQNVm2oWqmaM/XjuB/@/YvDxxs)
[Answer]
# [Aceto](https://github.com/aceto/aceto), ~~27~~ 25 bytes
1-based index.
```
;L[¥
`=]z
MLdI<
r!`;   p
```
We `r`ead the input and `M`emorize it (and directly `L`oad it again), then we negate it (`!`; leading to a truthy value only for an empty string). If this value is truthy (```), we jump to the end (`;`), where we `p`rint the implicit zero.
Otherwise, we increment the current stack value (initially a zero), duplicate it, and put one copy on the stack to the right, while also moving there (`Id]`). We then construct a decreasing range (`z`), join the stack as a string (`¥`), and move the value (and us) on the original stack again (`[`). We `L`oad the value we memorized earlier (the input) and compare it with this string. If equal, we jump to the end again, where we print the current "counter" value (`=`;`).
Otherwise, lots of empty space is traversed until the Hilbert curve eventually hits the `<` which puts the IP on top of `I` again, incrementing the counter and testing again.
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 16 bytes
```
r0({)_,s2$=!}g\;
```
[Try it online!](https://tio.run/##DY6xSkQBDAS/RbhC4YpkN5tNOPwTQcRCEK45S/Hbn68fZubz@@N@HI94/n15v/7g8vr09/V2O45IsNSezchMJLNS2emcXAQSAFEQGsZgGUyCZFFsmsOtqCwUq0rV5ZpahVIQVZJa1mg7OhvNrlZ3u6fX4TRMl@W2Pd6JycFwajQ9npnd2HNoz9ieoj2h3X8 "CJam – Try It Online")
## Alternative 16 bytes
```
r:V;0({)_,sV=!}g
```
[Try it online!](https://tio.run/##DY6xSkQBDAS/xe4Ei2ST3WwUf@NaEYuDg2u0FL/9@fphZr7un4/j@H69vsXl9/nj5ef6/vR3O45IVFPjzchMZGUnUznpXAQSQKFBCANjKyoLVdXFUk25tqOz0dXdbPW0exlMgsUmKQ7NVSgFlVqUNLJ2YnIwNT0czYxnHU7D5TYtj@3d2HNoz9ieoj2h3X8 "CJam – Try It Online")
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 13 bytes
```
q:Q,),{,sQ=}#
```
So many commas...
[Try it online!](https://tio.run/##DY4xSkZhDAQPYyW8IrubbBLBQ/xH@LETLMRSPPvz64eZ@fh8ft3399vjer1@r5/H@9/LfQeoLPcsAgAhJApGY7AMgqSYLJrN4SoEUVKqZLVGm5FIpjKz0tk5uRWFYqmyqlxdU@swTMvpst0eb0ej2ersanf39E4MhqPJqfH0zOzGnqE9sT2iPdCe5/gH "CJam – Try It Online")
### Explanation
```
q:Q            Read the input and store it in Q
   ,           Get its length
    ),         Get the range 0..n
      {,sQ=}#  Find the index of the first number in the range to satisfy this block:
       ,        Get the range 0..(number)-1
        s       Stringify it
         Q=     Check if it equals the input
```
[Answer]
# [Perl 6](https://perl6.org), ~~30 28~~ 27 bytes
```
{first :k,*eq$_,[\~] '',0...*}
```
[Test it](https://tio.run/##LY7LDoIwFET3/YqRNPJIbQokkFjRn3DnowssBl8gRRNj8NexiLvJzJ1zp9bNJekfRuOZ8FyS6wvTvDpoZP27KBvTYn5mgb5TxTbbzw6uywTnPOh@nbU2rSRF1UDAuggjhlAIhjhSaZLiTQBLpKZtkMHbU@XzU1Xe5N8/lvZBBkoVFoiFwGoFZ7jmtd3l@ZgtQZWDyQTOKCWx1dJg2OiNYJ/ZgI0wSbr@Cw "Perl 6 – Try It Online")
```
{[\~]('',0...*).first($_):k}
```
[Test it](https://tio.run/##LY7LDoIwFET3/YqRNFJMbQokkFiRn3DngwUWgy8IRRND8NexiLubO3NOptbNLRqeRuMViVyR@xvzvDppJEO3238OzHW5FEIsPFGUjWkZzbzVtf8RW21aRYqqgYStwA84fCk5wiCLoxgdAayPmrZBAna0qLhU5UP9/@fStDagNMMaoZRIUzhjW9R2FfOw3IBmDmYzONOpiEVLg3Ehm8QetwGfZIr0wxc "Perl 6 – Try It Online")
```
{first :k,$_,[\~] '',0...*}
```
[Test it](https://tio.run/##LY7dCoIwAIXv9xQnGamxxlRQaJkv0V0/uzCN9ac4C0Ls1W1md4fz83HqornFw9MUeMU8l@T@xjyvTgXSoSt1Y1qsrowqttt/DnBdJjjni/432BamlaSsGghYF0HIEAjBEIUqiRN0BLA4atoGKbwjVT6/VPoh//5ZW3oKShXWiIRAlsEZ27y2pzwfyw2ocjCbwZmkJHaqDcaD3gT2mQ3YBJOkH74 "Perl 6 – Try It Online")
## Expanded:
```
{  # bare block lambda with implicit parameter ｢$_｣
  first       # find the first one
  :k,         # return the index into the Seq instead of what matched
  $_          # that matches the input
  # from the following
  [\~]        # triangle reduce using &infix:«~» (string concatenation)
              # a Seq
    '',       #   that starts with an empty Str
    0         #   then a 0
    ...       #   generate values
    *         #   indefinitely
}
```
---
`'',0...*` produces an infinite sequence of values `''`,`0`,`1`,`2`,`3` …
`[\~] '',0...*` produces an infinite sequence of all of the possible inputs
```
""
"0"
"01"
"012"
"0123"
...
```
Note that this code will never stop if you give it an invalid input.
[Answer]
# [Pyth](https://pyth.readthedocs.io), ~~11~~ 10 bytes
1-indexed.
```
fqQ|jkSTk0
```
**[Try it here](https://pyth.herokuapp.com/?code=fqQ%7CjkSTk0&input=%22123456789101112%22&debug=0)**
If the empty string could be ignored, this can be shortened to **[6 bytes](https://pyth.herokuapp.com/?code=fqQsjk&input=%22123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100%22&debug=0)**:
```
fqQjkS
```
*-1 byte thanks to [@Mnemonic](https://codegolf.stackexchange.com/users/48543/mnemonic)*
[Answer]
# CJam, ~~14~~ ~~12~~ 11 bytes
```
q,_){,s,}%#
```
[Try it Online](http://cjam.aditsu.net/#code=q%2C_)%7B%2Cs%2C%7D%25%23&input=0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100)
```
q,   e# Get length of input string
_)   e# Duplicate length, increment by 1
{    e# Generate array by mapping [0,1,2,...,length] using the following function: 
,    e# Generate range [0,x] (x is the int we're mapping)
s    e# Convert range to string (e.g [0,1,2,3] => "0123"
,    e# Get the length of that string
}%   e# Map the int to the length of it's range string
#    e# Return the index of the length of the input string in the generated array
```
[Answer]
# [Dyvil](https://github.com/dyvil/dyvil), 42 38 bytes
```
s=>"".{var r=0;while($0!=s)$0++=r++;r}
```
Same algorithm as [this Java answer](https://codegolf.stackexchange.com/a/139869/42570), except it (ab)uses some of Dyvil's syntactic specialties.
Explanation:
```
s=>          // starts a lambda expression with one parameter
"".{         // begins a brace access expression, the value before the '.'
             // is available within the braces as a variable named '$0'
var r=0;     // variable with inferred type int
while($0!=s) // while the accumulator $0 does not (structurally) equal s
$0++=r++     // concatenate $0 and the String representation of r,
             // then store the result in $0 and increment r by 1
;            // end of while
r}           // return r as the result of the lambda
```
---
* **Saved `4` bytes by using a brace access expression instead of a variable for the accumulator**
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 47 bytes
```
do{$b=1..$a-join"";$a+=1}while($b-ne$args);$a-1
```
[Try it online!](https://tio.run/##DY5LasNAEAXvImYRE2T69b8JPoxMROwgrGAvvDA5@3i2xaNe/e3P9f64rNvW@/f@aucTjse2zL/79TZNX235POH/eblu60c7z7e1Lfefx2HwGb33CSxqHlkgAAyBwuAIJIqJwczCysbOwcklJBAWERUTl5CUUlIoq6iqqWtoahkZjE1MzcwtLK2cHM4urm7uHp5eQYHgkNCw8IjIqKREckpqWnpGZlZRjaAaZzVENUY1mml6Aw "PowerShell – Try It Online")
[Answer]
# [Arturo](https://arturo-lang.io), 31 bytes
```
$->s[0while[s<>join@1..<=]->1+]
```
[Try it!](http://arturo-lang.io/playground?NZGGxl)
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2), 4 [bytes](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)
```
ƘRJ=
```
[Try it online!](https://Not-Thonnu.github.io/run#aGVhZGVyPSZjb2RlPSVDNiU5OFJKJTNEJmZvb3Rlcj0maW5wdXQ9JTIyMTIzNDU2Nzg5MTAlMjImZmxhZ3M9)
## [Thunno 2](https://github.com/Thunno/Thunno2), 6 [bytes](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md)
```
żƒ€JȮ⁺
```
[Try it online!](https://Not-Thonnu.github.io/run#aGVhZGVyPSZjb2RlPSVDNSVCQyVDNiU5MiVFMiU4MiVBQ0olQzglQUUlRTIlODElQkEmZm9vdGVyPSZpbnB1dD0lMjIxMjM0NTY3ODkxMCUyMiZmbGFncz1l)
#### Explanation
```
ƘRJ=  # Implicit input
Ƙ     # First integer where:
 RJ   #  Join the range
   =  #  Equals the input?
      # Implicit output
```
```
żƒ€JȮ⁺  # Implicit input
ż       # Push [1..length]
 ƒ      # Prefixes of this list
  €J    # Join each into a string
    Ȯ⁺  # 1-based index of input
        # Implicit output
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 14 bytes
```
`@q:VXzGX=~}@q
```
1-indexed.
[Try it online!](https://tio.run/##DY47TkMBEMSOk3Y/MzuzSEjpuEGUEvqkiESFBFd/vN6y/fz6fhzH5/X1drv/fNzf/36vr@O4ZDU48mZkZmUnkjmpdG5FZVV1oVhTKtd2dHZ1N5o9rXYvAolCAyAGgrEMJotNkByK5k5MTk0PhjOj8axCqVILokaStQ6ny22YHsv2buw5tGdsT9Ge0J7PcfkH)
### Explanation
```
`       % Do...while
  @     %   Push iteration index (1-based), k
  q     %   Subtract 1: gives k-1
  :     %   Range: [1 2 ... k-1]. Will be empty for k=1
  V     %   Convert to string
  Xz    %   Remove spaces
  G     %   Push input
  X=    %   Are the two strings equal?
  ~     %   Negate. This is the loop condition. If true: next iteration
}       % Finally (execute at the end of the loop)
  @     %   Push k
  q     %   Subtract 1: gives k-1. This is the solution
        % End (implicit). Display (implicit)
```
[Answer]
## [C#](http://csharppad.com/gist/e40eb4a6e8d2e25dd319e0a8544afb1d), 72 bytes
---
### Data
* **Input** `String` `i` The int array to be deciphered
* **Output** `Int32` The number used to make the array
---
### Golfed
```
(string i)=>{int c,p=c=0;for(;p<i.Length;c++)p+=(c+"").Length;return c;}
```
---
### Ungolfed
```
( string i ) => {
    int
        c,
        p = c = 0;
    
    for( ; p < i.Length; c++ )
        p += ( c + "" ).Length;
    
    return c;
}
```
---
### Ungolfed readable
```
// Takes the string with the int array
( string i ) => {
    int
        c,         // Counter, it will count how many ints the array has.
        p = c = 0; // Padding, it will help jumping from int to int on the string.
    
    // Start counting. If 'i' is empty, the 'c' will be 0.
    for( ; p < i.Length; c++ )
    
        // Increase the number of digits with the length of 'c'.
        p += ( c + "" ).Length;
    
    // Return the counter.
    return c;
}
```
---
### Full code
```
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestBench {
    public static class Program {
        private static Func<String, Int32> f = ( string i ) => {
            int
                c,
                p = c = 0;
            for( ; p < i.Length; c++ )
                p += ( c + "" ).Length;
            return c;
        };
        
        static void Main( string[] args ) {
            List<String>
                testCases = new List<String>() {
                    "0123",
                    "0",
                    "",
                    "0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100",
                };
            
            foreach(String testCase in testCases) {
                Console.WriteLine($" Input: {testCase}\nOutput: {f(testCase)}\n");
            }
            Console.ReadLine();
        }
    }
}
```
---
]