-2
\$\begingroup\$

Inspired by this and this question

Challenge

Your challenge is to print any 100 consecutive digits of Champernowne's Constant. You must give the index at which that subsequence appears. The 0 at the beginning is not included.

For example, you could print any of the following:

+-----+----------------------------------------------------------------------------------------------------+
|Index|Output                                                                                              |
+-----+----------------------------------------------------------------------------------------------------+
|0    |1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545|
+-----+----------------------------------------------------------------------------------------------------+
|50   |0313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798|
+-----+----------------------------------------------------------------------------------------------------+
|100  |5565758596061662636465666768697071727374757677787980818283848586878889909192939495969798991001011021|
+-----+----------------------------------------------------------------------------------------------------+

Rules

  • Output may be a string/digit list/etc.

  • You may provide a function or a program

  • This is , so the shortest code wins!

\$\endgroup\$
4
  • 9
    \$\begingroup\$ Since Champerone's constant is normal, you can output any 100 digits, as long as you know the index where they appear. \$\endgroup\$
    – Neil
    Commented Dec 8, 2023 at 18:05
  • \$\begingroup\$ @Neil Ah okay that makes sense, I couldn't remember if it was normal or not, so I think I just guessed. \$\endgroup\$
    – CrSb0001
    Commented Dec 8, 2023 at 18:07
  • 16
    \$\begingroup\$ This is a chameleon challenge for "print any 100 digits". \$\endgroup\$
    – xnor
    Commented Dec 8, 2023 at 18:43
  • 2
    \$\begingroup\$ @Neil and the calculation of that index is trivial \$\endgroup\$
    – Seggan
    Commented Dec 8, 2023 at 18:45

11 Answers 11

9
\$\begingroup\$

Jelly,  4 3  2 bytes

³Ṭ

A full program that accepts no arguments and prints a list of one hundred consecutive places starting at the 0-indexed index (you may need to scroll):

$$98888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888890$$

Try it online!

How?

By definition, Champernowne's constant's decimal places are the concatenation of the natural numbers, so \$10^{99}\$, the first number with \$100\$ decimal digits, appears.

The index of \$N = 10^{99}\$ may be calculated like so:

$$d = \text{digit_length}(N) = \lfloor log_{10}(N) \rfloor + 1$$ $$\text{index} = d \times N - \frac{10^{d}-1}{9}$$ $$= 100 \times 10^{99}-\frac{10^{100}-1}{9}$$ $$= 10^{101}-\frac{10^{100}-1}{9}$$ $$=98888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888889$$

The next digit of Champernowne's constant after the last zero of \$N\$ is the first digit of \$N+1\$ which is \$1\$, so let's get the trailing \$99\$ zeros of \$N\$ and a \$1\$...

³Ṭ - Main Link: no arguments
³  - 100
 Ṭ - untruth -> [0,0,0,...,1] (99 zeros followed by a one)
   - implicit print

Original @ 4 bytes:

55ḊV

A full program that accepts no arguments and prints the 2nd to 101st decimal places.

Try it online!

How?

55ḊV - Main Link: no arguments
55   - fifty-five
  Ḋ  - dequeue -> [2,3,4,...,54,55]
   V - evaluate as Jelly code -> (integer) 234...5455
     - implicit print
\$\endgroup\$
1
  • 2
    \$\begingroup\$ Oh, dammit, that's clever lol. Also I'll have to keep using V to flatten digits into a number in mind, that's a cool trick. \$\endgroup\$
    – hyper-neutrino
    Commented Dec 8, 2023 at 19:58
7
\$\begingroup\$

C, 41 bytes

main(i){for(i=9;i++<59;)printf("%d",i);}

Goes through numbers 10 to 59 (indexes 9 to 108), printing exactly 100 digits (without a newline).


C, 28 bytes

main(){printf("1%099d",0);}

Inspired by Jonathan Allan's solution, just prints 10^99, starting at index 98888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888889 (if my short Python script did not fail me :p):

n = 0

for i in range(1, 100):
  n = n + 9 * pow(10, i - 1) * i

print(n)
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Welcome to Code Golf, and nice answer! \$\endgroup\$ Commented Dec 8, 2023 at 18:09
  • 1
    \$\begingroup\$ @RydwolfPrograms Thanks! \$\endgroup\$ Commented Dec 8, 2023 at 18:19
6
\$\begingroup\$

brainfuck, 23 bytes

-[----->+>+<<]>-[->..<]

Try it online!

Outputs 100 3s, which appears at index 16888888888888888888888888888888888888888888888888872.

This program first obtains the value 51 (which is the ASCII code of 3), calculating it as 255/5, in two cells. It then decrements one of those cells to 50, and then uses it as a counter for a loop in which each iteration outputs the other cell's value twice.

\$\endgroup\$
4
\$\begingroup\$

Jelly, 6 bytes

2r55DF

Try it online!

Starts at index 1 (digit 2 in the number 2). Range from 2 to 55 and then the decimal representation of each, then flattened.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Haha - I didn't golf this and make a post in 9 seconds. \$\endgroup\$ Commented Dec 8, 2023 at 17:55
  • 1
    \$\begingroup\$ @JonathanAllan I knew there was something I was missing in place of DF lmao. Also yeah not sure why I didn't think of using dequeue directly on 55; I thought I'd have to do 55RḊ; my rustiness is showing xD \$\endgroup\$
    – hyper-neutrino
    Commented Dec 8, 2023 at 19:59
3
\$\begingroup\$

Charcoal, 6 bytes

⭆⁵⁰⁺χι

Try it online! Link is to verbose version of code. Starts at index 9. Explanation: Loops over the first 50 integers adding 10 to each, then joins everything together.

Alternative version, also 6 bytes:

⪫…χ⁶⁰ω

Try it online! Link is to verbose version of code. Starts at index 9. Explanation: Lists the integers from 10 to 60, then joins everything together.

Alternatively, starting at index 1, also for 6 bytes:

⭆⁵⁴⁺²ι

Try it online! Link is to verbose version of code. Explanation: Loops over the first 54 integers adding 2 to each, then joins everything together.

Boring 4-byte solution:

”);e

Try it online! Link is to verbose version of code. Starts at index 988888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888890. Explanation: Compressed string of 100 0s.

Slightly less boring 5-byte solution:

IXφ³³

Try it online! Link is to verbose version of code. Starts at index 98888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888889. Explanation: Calculates 1000³³.

\$\endgroup\$
3
\$\begingroup\$

05AB1E, 5 3 bytes

1т×

-2 bytes porting @Tbw's APL answer.

Outputs at 0-based index \$55555555555555555555555555555555555555555555555555551\$.

Try it online.

Original 5 bytes answer(s):

Here also the program with an infinite list of all valid outputs:

∞Sü100J

Try it online.

Explanation:

1т      # Push 1; Push 100
  ×     # Pop both, and push a string of 100 1s
        # (which is output implicitly as result)

Y55     # Push 2; Push 55
   Ÿ    # Pop both, and push a list in the range [2,55]
    J   # Join the list together to a single string
        # (which is output implicitly as result)

T59     # Push 10; Push 59
   ŸJ   # Same as above

46₃     # Push 46; Push 95
   ŸJ   # Same as above
∞       # Push an infinite positive list: [1,2,3,...]
 S      # Convert it to a flattened list of digits
  ü100  # Pop and push a list of all overlapping lists of 100 digits
      J # Join each inner list of digits together to a string
        # (after which this infinite list is output implicitly)
\$\endgroup\$
3
\$\begingroup\$

APL (Dyalog Classic), 5 bytes

100⍴1

Try it online!

Prints 1, one hundred times. Similar approach to @Jonathan Allan and others. First appears as

1111111111111111111111111111111111111111111111111 #fifty-one 1s
11111111111111111111111111111111111111111111111(12)

Index is \$51\cdot\frac{10^{51}-1}{9}+ \sum_{n=1}^{50}(9n \cdot 10^{n}) = \frac{5}{9}(10^{53}-1)-4\$. Explicitly, this is \$55555555555555555555555555555555555555555555555555551\$ (fifty-one 5s and one 1).

7 bytes

If we want to print as a string rather than a list.

100⍴'1'

Here's a more legit APL solution by Graham

\$\endgroup\$
2
\$\begingroup\$

Vyxal H, 14 bitsv2, 1.75 bytes

1ẋ

Try it Online!

Bitstring:

01000010111110

Prints 1 100 times, same as APL

\$\endgroup\$
2
\$\begingroup\$

///, 17 bytes

/10/00000001/1100

Try it online!

Outputs 98 0s followed by 2 1s, which appears (in 1[000...0001 1]000...0002) at index 98888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888990.

The replacement multiplies the number of 0s by 7 as they move across each 1.


Some alternative solutions, of the same length:

/10/0001/10010110

Try it online!

Outputs 96 0s followed by 4 1s.

/10/00001/0110010

Try it online!

Outputs 97 0s followed by 3 1s.

\$\endgroup\$
2
\$\begingroup\$

APL+WIN, 11 10 bytes

i byte saved thank to Tbw

A function taking no arguments with output from index 2 with index origin = 1

1↓⊃,/⍕¨⍳55

Try it online! Thanks to Dyalog Classic

\$\endgroup\$
2
  • \$\begingroup\$ You can save a byte by dropping the high minus ¯. Then you get one index over by starting at 2. \$\endgroup\$
    – Tbw
    Commented Dec 10, 2023 at 0:04
  • \$\begingroup\$ @Tbw Thanks. Code edited. \$\endgroup\$
    – Graham
    Commented Dec 10, 2023 at 10:16
1
\$\begingroup\$

GolfScript, 6 bytes

55,(;5

Try it online!

Prints the first 100 digits.

55,    # the list 0..55
   (;  # drop the 0
     5 # push 5 to the stack
# the stack is implicitly printed without separator

Alternatively, this one prints a hundred 1s:

GolfScript, 6 bytes

1+100*

Try it online!

Gets "1" by appending 1 to the implicit empty input, then repeats it 100 times.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.