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

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Find the number in the Champernowne constant

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 , 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*

Draft saved
Draft discarded
Cancel
2
  • 1
    \$\begingroup\$ -1 \$\endgroup\$ Commented Nov 13, 2020 at 16:24
  • 1
    \$\begingroup\$ @Razetime Knew how you did it before I clicked the link! \$\endgroup\$ Commented Nov 13, 2020 at 16:28

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