Your challenge is to print any 100 consecutive digits of π. You must give the index at which that subsequence appears. The 3 is not included.

For example, you could print any of the following:

  • 1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 (index 0)
  • 8214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196 (index 100)
  • 4428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273 (index 200)

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

To ensure answers actually produce known digits of pi, all answers must be verifiable through the Pi API (note: This API counts the 3, your answer should not).

This is , shortest wins!

  • 1
    \$\begingroup\$ Does we need to actually run our code to completion, or can it be really slow? \$\endgroup\$
    – xnor
    Oct 1, 2023 at 2:42
  • 7
    \$\begingroup\$ But theoretically any sequence of integers eventually occurs in pi at some point... \$\endgroup\$ Oct 1, 2023 at 6:03
  • 2
    \$\begingroup\$ @ShiranYuan But that would probably require calculating a googol digits of π to find out where that sequence starts. \$\endgroup\$
    – Neil
    Oct 1, 2023 at 6:35
  • 4
    \$\begingroup\$ Here are some experiments on the compression of pi digits (in binary format) by a fellow Intellivision game developer. TLDR: using standard compression algorithms is pointless. \$\endgroup\$
    – Arnauld
    Oct 1, 2023 at 18:56
  • 4
    \$\begingroup\$ @ShiranYuan Theoretically it is still unknown if pi is normal :) (doi.org/10.1080/10586458.2002.10504704) \$\endgroup\$ Oct 2, 2023 at 1:07

11 Answers 11


JavaScript (ES11), 53 bytes

Starts at index 0. Returns a BigInt.


Try it online!

The underlying formula is:


(also used in my answer to this other challenge)


Trivial answers

This is mostly for answers that use a built-in arbitrary-precision pi constant, or a built-in that generates digits of pi.

Python 3, 49 bytes

from mpmath import*

Try it online!

05AB1E, 5 bytes


Try it online!

Vyxal H, 18 bitsv2, 2.25 bytes


Try it Online!


ɾ∆i­⁡​‎  # ‎⁡The H flag presets the stack to 100
ɾ    # ‎⁢For each number in the range [1, 100]:
 ∆i  # ‎⁣Push the nth digit of pi, 0 indexed, hence avoiding the `3`

Created with the help of Luminespire.

M, 12 bytes


Try it online!

Wolfram Language (Mathematica), 31 bytes


Try it online!

Charcoal, 13 bytes


Try it online! Link is to verbose version of code. Starts at the 997th digit of π. Explanation:


Make space for 1999 characters in the canvas.


Fill those characters with the digits of π, including the leading 3., so 1997 decimals.


Take only the 100 digits starting at the 997th.

Ruby, 53 bytes

BigMath.PI guarantees accuracy for a number of digits up to its argument, but it outputs more digits than that (requiring truncation), and it just so happens that BigMath.PI(99) is still accurate enough for the problem, saving a byte over BigMath.PI(101).

p BigMath.PI(99).to_s[3,100]

Attempt This Online!

  • 3
    \$\begingroup\$ People, don't upvote the CW, bringing it up on the vote list makes much cooler answers get less attention \$\endgroup\$
    – noodle man
    Oct 1, 2023 at 13:50
  • 1
    \$\begingroup\$ I would note that mpmath is an external python library rather than in the standard libs \$\endgroup\$
    – Jo King
    Oct 5, 2023 at 22:54

Charcoal, 32 bytes


Try it online! Link is to verbose version of code. Explanation: Calculates the first 1001 terms of 2 + 1/3*(2 + 2/5*(2 + 3/7*(2 + 4/9*(2 + ...)))).


Calculate 2e100 as an integer.


Start with that as an approximation to 1e100π.


Repeat 1000 times.


Calculate the next approximation to π.


Output without the leading 3.

  • \$\begingroup\$ I tried other formulae but they were usually longer and would also have needed to compute extra digits or have a correction value added. Also for comparison string compression results in a 45 byte program. \$\endgroup\$
    – Neil
    Oct 1, 2023 at 16:08

Python2, 91 bytes

print 0x296e417278c91bbebb472cab663a71405eef415a7751d7b251874642e34fa5406ba944ce62eb559eff7

Prints the first 100 digits starting at index 0.

  • \$\begingroup\$ Sadly, noting that 0x296e417278c91bbebb472cab663a71405eef415a7751d7b251874642e34fa5406ba944ce62eb559eff7 == 9*117127*3643891*0xbdbf77d0b437e74747cd86c65905fc322c302b55f1756ff0169afdbfcebffea23ca51e5 is not helpful, because if c==a*b then c never has more digits than a*b \$\endgroup\$
    – Stef
    Oct 3, 2023 at 13:43
  • 2
    \$\begingroup\$ I just checked 51197 digits of pi to see if any indexes other than 0 would be shorter, and they weren't. Clever and well done, even if it won't win a prize. \$\endgroup\$ Oct 5, 2023 at 1:22
  • \$\begingroup\$ @MarkRansom It could be possible to save bytes if there was a perfect square or power somewhere, ie writing 50digitnumber**2+smallremainder instead of 100digitnumber. But if the remainder also has 50 digits then it's useless. \$\endgroup\$
    – Stef
    Oct 5, 2023 at 11:35
  • 1
    \$\begingroup\$ Unfortunately I couldn't find a sequence that was even close to a perfect square. The best was at index 8328 but it would require 94 characters after adding the remainder. \$\endgroup\$ Oct 5, 2023 at 11:51
  • 1
    \$\begingroup\$ I was thinking about what it would take to find a perfect square. Every 50-digit number can be squared to create a 100-digit number. But that means your chances are 1 in 10^50. Even for a million tries your odds are still only 1 in 10^44. Your odds of winning the Powerball jackpot 5 times in a row are higher. \$\endgroup\$ Oct 6, 2023 at 1:58

Octave, 24 bytes

Prints 100 digits of pi, starting at index 2


Try it online!

MATLAB, 30 28 bytes


For both versions, this first uses variable precision calculation to work out Pi exactly to 102 digits (not decimals, it includes the 3).

Then it converts the result to a character vector and removes the string prefix '3.1' to leave exactly 100 characters. For the Octave version we can index directly into the returned value from the char() function, while MATLAB we have to save to a variable then truncate.

ans =


  • We have to use 102 instead of 101 (3 + 100 decimals), because the vpa function rounds the final digit. If we used 101 the final digit would be incorrect due to rounding.
  • Based on this meta post, when output is allowed to return a string, the ans= is acceptable.
  • 2
    \$\begingroup\$ @LuisMendo Ah yea, I'm used to wrapping in @() to avoid the ans= hence my mind was programmed to avoid the array access. In this case we are required to return a string (rather than STDOUT), which means the ans= appears to be allowed. \$\endgroup\$ Oct 2, 2023 at 10:58

Kamilalisp, 21 bytes

↓ 2\⍫← \○⊢*(fr 101)\π

Attempt This Online!


Python 3, 165 bytes

(index 0)

for c in range(364,0,-14):
 for b in range(c,0,-1):

Try it in SageMathCell (with verification).

This algorithm only uses integer arithmetic. It was derived from obfuscated C code by Dik T. Winter, but I've modified it a bit over the years. Dik's version was a bit more compact, and can generate hundreds of digits, but it eventually produces erroneous output due to integer overflow, which isn't an issue in Python. OTOH, this algorithm gets a bit sluggish for large numbers of digits, due to the O(n^2) inner loop.

Of course, for serious pi digit generation, there are various lovely AGM based algorithms that converge quadratically. The Borwein brothers found several, but I like the Gauss / Brent / Salamin https://stackoverflow.com/a/26478803/4014959


Java 10, 176 171 bytes

v->{var t=java.math.BigInteger.TEN.pow(100).shiftLeft(1);var p=t;for(int i=330;i>0;)p=t.add(p.multiply(t.valueOf(i)).divide(t.valueOf(i-~i--)));return(p+"").substring(1);}

Based on my answer for the related challenge of outputting the first 500 digits of pi.
-5 bytes thanks to @Neil by reverting the algorithm

Try it online.

  • 1
    \$\begingroup\$ Calculating in reverse increases accuracy allowing you to save bytes: Try it online! \$\endgroup\$
    – Neil
    Oct 4, 2023 at 21:21

05AB1E, 45 44 bytes


Try it online! Starts at index \$2{,}164{,}164{,}669{,}331\$.

  • 1
    \$\begingroup\$ This is nice, and (I think) the first answer to actually exploit 'compression' by choice of position. It would be 40.5 bytes by porting to Nibbles, but you deserve the credit for this & I won't post it separately... \$\endgroup\$ Oct 10, 2023 at 8:26

Vyxal, 70 bitsv2, 8.75 bytes


Try it Online!

Calculates pi through \$cos^{-1}(-1)\$ and then formats to 100 decimal places.


u∆C        # ‎⁡arccos(-1)
   ₁⇧Ḟ     # ‎⁢Formatted to 102 decimal places
      ḢḢ   # ‎⁣Remove the `3.`
        Ṫ  # ‎⁤and the last digit. The last digit is needed for rounding purposes.

Created with the help of Luminespire.


Python 3, 256 bytes

This version computes pi using an accelerated version of Archimedes' algorithm for pi = 4*arctan(1).

def s(y,x=M):
 while u<0 or u>1:u=(x//2+y)//x-x;x+=u>>1
 return x
for i in range(16):
 for u in p:q+=2;d+=[d[-1]-(u>>q)]

Try it in SageMathCell

This code implements binary fixed point arithmetic using Python integers. The core arctan algorithm was devised by Bille Carlson, see Carlson, B. C. An Algorithm for Computing Logarithms and Arctangents, Mathematics of Computation, Apr 1972.

This algorithm rapidly calculates any of the standard inverse circular and hyperbolic functions. It even handles complex arguments (assuming the sqrt function does). Here's a non-golfed demo that computes pi = 10*arcsin((sqrt(5)-1)/4).

This algorithm is very similar to the AGM (arithmetic-geometric mean), but it updates the two core terms a and g sequentially instead of in parallel. So it's sometimes referred to as the fake AGM. It's also known as Borchardt's modified AGM algorithm. The Borwein brothers pointed out that it is, in fact, the same algorithm Archimedes used to iteratively subdivide a polygon.

Carlson's innovation is to apply Richardson series acceleration, which speeds up the convergence considerably. It's not as fast as a true AGM, however it's quite efficient for high precision calculation because it only uses one non-trivial division. (The square root can be also be implemented to avoid non-trivial divisions, using the Quake-style 1/sqrt algorithm).

For further details on algorithms related to pi and the AGM, please see The Borwein brothers, Pi and the AGM by Richard P. Brent.

FWIW, Carlson also developed and analysed a suite of true AGM algorithms for computing elliptic integrals and functions, and those algorithms can (of course) handle circular & hyperbolic functions. See Numerical computation of real or complex elliptic integrals


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.