[Question]
  [
### Introduction
In base 10, the Champernowne constant is defined by concatenating representations of successive integers. In base 10: `0.1234567891011121314151617...` and so on.
You can see that the first appearence of `15` starts at the `20th` decimal:
```
  Position
  0000000001111111111222222222233333333334444444444555555555566666666
  1234567890123456789012345678901234567890123456789012345678901234567
                     ^
0.1234567891011121314151617181920212223242526272829303132333435363738...
                     ^^
                     15 = position 20
```
The first appearence of `45` starts at the `4th` decimal:
```
  Position
  0000000001111111111222222222233333333334444444444555555555566666666
  1234567890123456789012345678901234567890123456789012345678901234567
     ^               
0.1234567891011121314151617181920212223242526272829303132333435363738...
     ^^
     45 = position 4
```
So, the task is easy. Given a non-negative integer, output the position of the integer in the Champernowne constant.
### Rules
* You may provide a function or a program
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the submission with the least amount of bytes wins!
### Test cases
```
Input: 20
Output: 30
Input: 333
Output: 56
Input: 0
Output: 11 (note that the 0 before the decimal point is ignored)
Input: 2930
Output: 48
```
  
[Answer]
# LabVIEW, 29 [LabVIEW Primitives](https://codegolf.meta.stackexchange.com/a/7589/39490)
This uses strings for now. It matches the input as a pattern and outputs the offset - (input lenght -1).
[![](https://i.stack.imgur.com/wGdn4.gif)](https://i.stack.imgur.com/wGdn4.gif)
[Answer]
# Pyth, 10
```
hxjkS+QT`Q
```
Concatenates first `input + 10` numbers then finds the 0 based index plus one.. The extra ten are only needed for 0.
[Test Suite](http://pyth.herokuapp.com/?code=hxjkS%2BQT%60Q&input=2930&test_suite=1&test_suite_input=0%0A1%0A15%0A20%0A333%0A2930&debug=0)
[Answer]
# Javascript, 57 bytes
```
a=prompt();for(y=b=" ";y<a+11;)b+=++y;alert(b.indexOf(a))
```
Saved 1 byte thanks to Conor O'Brien.
[Answer]
## Haskell, 62 bytes
```
a#b|and$zipWith(==)a b=1|1<2=1+a#tail b 
(#(show=<<[1..])).show
```
Usage example: `(#(show=<<[1..])).show $ 2930`-> `48`.
How it works: `a # b` finds the position of `a` within `b`: if `a` is prefix of `b` return `1`, else add `1`to a recursive call with `a # tail b`. The pointfree function `(#(show=<<[1..])).show` expects an (unnamed) argument `n` and calls `show n # show=<<[1..]`.
The function `subIndex` would also do the job of `#`, but the required `import Data.List.Utils` doesn't pay off.
[Answer]
# Ruby, 28
```
->n{[*0..n+10]*''=~/\B#{n}/}
```
Includes a 0 at the beginning so that matches are 1-indexed, but uses `\B` to require that the match not be at the beginning of the string.
[Answer]
# Japt, 11 bytes
This was originally beating Pyth, but apparently it didn't work for input `0`.
```
1+1oU+B ¬¨bU
```
[Try it online!](http://ethproductions.github.io/japt?v=master&code=MSsxb1UrQiCsYlU=&input=MTAx)
### How it works
```
1+1oU+B ¬¨ bU
1+1oU+B q bU  // Implicit: U = input integer
  1oU+B       // Generate the range [0, U+11).
        q bU  // Join and take the index of U.
1+            // Add one to get the correct result.
              // Implicit: output last expression
```
[Answer]
# Lua, 54 Bytes
```
s=""for i=1,1e4 do s=s..i end print(s:find(io.read()))
```
Note: ~~Currently this program prints both the first occurrence of the first char of the string, and the point where it ends. If this is not allowed, it will cost a few more bytes.~~ I would like to petition for a bonus because my program prints out both the first position and last position of the input number.
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 22 bytes
```
it10+:Yst' '=~)wYsXf1)
```
Take the input (`i`), make the vector 1 to input+10 (`10+:`), converts the vector to a string (`Ys`), and remove the spaces, which is painful, (`t' '=~)`). Then, convert the input to a string (`Ys`), find where the input string is in the string of numbers (`Xf`) and take the first location (`1)`). The `t`'s and `w`'s are manipulating the stack (duplicate and swap, respectively).
[Answer]
# PowerShell, 39 44 bytes
[Edit: my assumption doesn't hold, building an array from 1-0 doesn't find 0 at place 11. Instead, build from 1-x+10 to handle 0 as well, now 44 bytes]
```
param($i)(1..($i+10)-join'').IndexOf("$i")+1
```
---
You will always find *x* when building a string of the Champernowne constant at the latest point when you add *x* onto the end, so an array from 1-x will always have the answer in it. The question becomes *"does it occur any sooner than that?"*. This code
```
param($i)(1..$i-join'').IndexOf("$i")+1
e.g.
PS C:\Temp> .\Champer.ps1 20
30
```
generates a range of numbers, casts it to a string, and searches for the parameter inside it. Because PowerShell is an object oriented shell, the parameter is actually an `[int]` type, so trying to save two characters with `.IndexOf($i)` would search the string for an integer and find nothing. That's why I use string interpolation `"$i"`.
[Answer]
# [MATL](https://esolangs.org/wiki/MATL) (release 1.0.1), 22 bytes
```
iXK10+:"@Ys]N$hKYsXf1)
```
### Example
```
>> matl iXK10+:"@Ys]N$hKYsXf1)
> 333
56
```
### Explanation
```
i       % Input
XK      % Copy to clipboard K            
10+     % Add 10. This is needed in case input is 0
:       % Vector of equally spaced values, starting from 1
"       % For each
  @Ys   %   For loop variable as a string
]       % End                            
N$h     % Horizontal concatenation of all stack contents
KYs     % Paste from clipboard K (input number) and convert to string
Xf      % Find one string within another 
1)      % First value
```
# [MATL](https://github.com/lmendo/MATL) (release 20.8.0), 16 bytes (language postdates challenge)
*Credit to @Giuseppe for this version of the program (slightly modified)*
```
10+:"@V]&hGVXf1)
```
[Try it online!](https://tio.run/##y00syfn/39BA20rJISxWLcM9LCLNUPP/f2NjYwA)
### Explanation
```
10+     % Implicit Input. Add 10. This is needed in case input is 0 
:       % Vector of equally spaced values, starting from 1
"       % For each
  @V    %   For loop variable as a string 
]       % End
&h      % Horizontal concatenation of all stack contents
GV      % Paste from automatic clipboard G (input number) and convert to string
Xf      % Find one string within another 
1)      % First value
```
[Answer]
## PowerShell, ~~54~~ 50 Bytes
```
for($c='';!($x=$c.IndexOf("$args")+1)){$c+=++$i}$x
```
Thanks to [TessellatingHeckler](https://codegolf.stackexchange.com/users/571/tessellatingheckler) for the idea of swapping the `while` loop for a `for` loop.
Executes via a `for` loop. As with other languages, the first statement in the loop can construct variables and assignments, so this starts with `$c` equal to just the empty string `''` so that we have zero-indexing of the string lining up with the decimal indexing of the challenge. We're then in a loop that checks whether `$c` has the input integer (`$args`) somewhere within it (i.e., since `.IndexOf()` returns `-1` if the string isn't found, we add one to that (`0`) and not it (`$TRUE`) to continue the loop). If it's not found, we add on our pre-incremented `$i` counter variable, then recheck the string. Once the string is found, `.IndexOf()` will return a positive value, the not of which will be `$FALSE`, breaking out of the loop. Finally, we output the index with `$x`.
[Answer]
# JavaScript (ES6), 40 bytes
```
x=>(f=n=>n?f(n-1)+n:" ")(x+11).search(x)
```
Uses the recursive function `f` to avoid loops. The [search](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search) method works the same as `indexOf` except that it takes a RegExp as a parameter, which is irrelevant for this challenge.
Adding a `" "` for the `n=0` case (zero is falsy in JS) coerces the `+` to perform string concatenation instead of addition, and corrects for zero-based indexing.
[Answer]
# Python 3, 54.
```
print(''.join(map(str,range(1,9**7))).find(input())+1)
```
[Answer]
## CJam, 11 bytes
```
r_i),s\#Be|
```
[Test it here.](http://cjam.aditsu.net/#code=r_i)%2Cs%5C%23Be%7C&input=15)
I'm finding the position of `N` in the string `01234...N` to account for the 1-based indexing. Finally I fix `0` by applying logical OR with 11.
[Answer]
## Seriously, 13 bytes
```
;‚âà9u+R`$`MŒ£√≠
```
Takes input as an integer. Contains unprintables, so hexdump:
```
0c3bf739752b526024604de4a1
```
[Try it online](http://seriouslylang.herokuapp.com/link/code=0c3bf739752b526024604de4a1&input=5)
Explanation:
```
;‚âà9u+R`$`MŒ£√≠
<form feed>   push str(input)
;‚âà9u+R        dupe, push [1,...,input+10]
      `$`MŒ£   string concatenation of list
           √≠  get index of input
```
[Answer]
# ùîºùïäùïÑùïöùïü, 13 chars / 22 bytes
```
1+‚©•(1,√Ø+·∏ã)‚®ù√ø√Ø
```
`[Try it here (Firefox only).](http://molarmanful.github.io/ESMin/interpreter.html?eval=true&input=20&code=1%2B%E2%A9%A5%281%2C%C3%AF%2B%E1%B8%8B%29%E2%A8%9D%C3%BF%C3%AF)`
[Answer]
## k4, 21 bytes
```
{*1+(,/$1+!10+x)ss$x}
```
Same algo as everyone else‚Äîconcatenate `[1..10+x]` as strings, search for x as string, convert to one-based indexing, return first hit.
Checking the test cases:
```
  &/20 4 30 56 11 48={*1+(,/$1+!10+x)ss$x}'15 45 20 333 0 2930
1b
```
[Answer]
# Mathematica, 101 bytes
```
(If[#==0,11,m=Min@SequencePosition[s=Flatten[(K=IntegerDigits)/@Range[0,#]],K@#];Length@s[[;;m-1]]])&
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~82~~ ~~73~~ 55 bytes
*Migrated from [the duplicate](https://codegolf.stackexchange.com/questions/137474/champernowne-up-to-me)*
```
x!b|or$zipWith(==)x b=0
x!(_:b)=1+x!b
(!(show=<<[1..]))
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/v0IxqSa/SKUqsyA8syRDw9ZWs0IhydaAq0JRI94qSdPWUBuogivdVkNRozgjv9zWxibaUE8vVlPzf25iZp5tQVFmXolKupKlodJ/AA "Haskell ‚Äì Try It Online")
## Explanation
First we define `!`. `x!b` truncates `b` to the first appearance of `x`. It does this by checking if `b` starts with `x` (`or$zipWith(==)x b`) returning `x` if it does and moving one down the string otherwise. Then we define our main function. Our main function is a point-free function that takes the constant (`show=<<[1..]`) and truncates it to the first appearance of `x`. This takes `x` as a string.
[Answer]
# JavaScript (ES6), ~~50~~ ~~39~~ 38 bytes
```
x=s=``
f=n=>-~s.search(n)||f(n,s+=++x)
```
---
## Try it
```
x=s=``
f=n=>-~s.search(n)||f(n,s+=++x)
o.innerText=f(i.value=15);oninput=_=>o.innerText=f(+i.value)
```
```
<input id=i type=number><pre id=o></pre>
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
```
+‚ÅµRVw
```
[Try it online!](https://tio.run/##y0rNyan8/1/7UePWoLDy////GwAA "Jelly ‚Äì Try It Online")
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 6 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
‚åê‚ïõ‚àô#¬ª‚ñì
```
[Run and debug it](https://staxlang.xyz/#p=a9bef923afb2&i=20%0A333%0A0%0A2930&a=1&m=2)
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 26 bytes
```
{[~](0..$_).index($_)||11}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYKvwvzq6LlbDQE9PJV5TLzMvJbVCA8iqqTE0rP2fll@kYGiqY2KqY2SgY2xsrGOgY2RpbKBQzaWgoFCcWKmgp5bGVfsfAA "Perl 6 ‚Äì Try It Online")
Finds the index of the element in the concatenated range from 0 to that element, or `11` if the number is a zero
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~6~~ 5 bytes
```
‚Ç¨·πÅdNd
```
[Try it online!](https://tio.run/##yygtzv7//1HTmoc7G1P8Uv7//29hDgA "Husk ‚Äì Try It Online")
*-1 thanks to Razetime*
```
‚Ç¨        The 1-based index, in
  d      decimal digits
 ·πÅ       concat-mapped over
   N     all natural numbers,
    d    of the decimal digits of the input.
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 6 bytes
```
nLJsk>
```
[Try it online!](https://tio.run/##MzBNTDJM/f8/z8erONvu/39jY2MA "05AB1E ‚Äì Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 6 bytes
```
‚ÇÅ+…æ·πÖ·∏ü‚Ä∫
```
[Try it Online!](https://vyxal.pythonanywhere.com/?v=2#WyJBIiwiIiwi4oKBK8m+4bmF4bif4oC6IiwiIiwiMjBcbjMzM1xuMCJd) `…æ·πÖ·∏ü` would be enough if not for the zero edgecase.
```
‚ÇÅ+…æ·πÖ·∏ü‚Ä∫
     ‚Ä∫ # 1 + 
    ·∏ü  # Index of input in
   ·πÖ   # Concatenation of
  …æ    # 0...
‚ÇÅ+     # 100+n
```
[Answer]
# [Perl 6/Rakudo](https://perl6.org/) 29 bytes
```
{$_~=$++until /(.+)$^a/;$0.chars}
```
Defines a function with one input ($^a). Call thus:
```
say {$_~=$++until /(.+)$^a/;$0.chars}(333)
> 56
```
Appending `$`, an anonymous variable, incrementing `$++` until the input `$^a` is found, and then counting the number of chars before it. Requiring at least 1 char before it `.+` in the regex usefully excludes the 0->0 case
[Answer]
# J, 30 Bytes
```
{.I.(":E.[:}.' '-.~":@i.@+&11)
```
Could probably be golfed down a bit more, specifically in concatenating the first n+10 integers.
### Explanation:
```
{.I.(":E.[:}.' '-.~":@i.@+&11)
                      i.@+&11   | Integers 0 to n+10
                   ":@          | Format list to string
             ' '-.~             | Strip spaces
           }.                   | Behead (remove leading 0)
         [:                     | Cap (previous verbs executed in order, not as a fork)
     ":E.                       | Find matches to the string n (returns a boolean vector)
  I.                            | Indexes of 1s
{.                              | Take only the first
```
Note that this is 0-indexed. Examples:
```
    {.I.(":E.[:}.' '-.~":@i.@+&11) 1
0
    {.I.(":E.[:}.' '-.~":@i.@+&11) 0
10
    {.I.(":E.[:}.' '-.~":@i.@+&11) 333
55
```
[Answer]
# [Perl 5](https://www.perl.org/), ~~42~~ 31 + 1 (-p) = 32 bytes
```
(join'',0..$_+10)=~/$_/;$_="@-"
```
[Try it online!](https://tio.run/##K0gtyjH9/18jKz8zT11dx0BPTyVe29BA07ZOXyVe31ol3lbJQVfp/38jS2ODf/kFJZn5ecX/dX1N9QwMDf7rFgAA "Perl 5 ‚Äì Try It Online")
**Explanation**
```
(join'',0..$_+10)   # concatenate all of the numbers from 0 to 10 over the input
=~/$_/;             # skip the first 0, then find the input
$_="@-"             # @- holds the index of the start of the last match
```
]