Your challenge is to print x digits of pi where x is your code length.


Source code (length) -> output
foo!        (4)         3.141
foobar      (6)         3.14159
kinda long  (10)        3.141592653
+++++       (5)         3.1415
123456789   (9)         3.14159265

You can use floor(π/10 * 10code_length) / 10code_length - 1 to determine the number of digits you need to print. Note that the decimal point does not count as a digit of pi - so code of length 3 should have output 3.14, of length 4.


  • Your code length must be larger than three characters.
  • You may not use any standard loopholes.
  • You may use any standard allowed output methods.
  • You may not read your source to determine code length.
  • You may not use a builtin pi constant.
  • Pi must be completely accurate and not approximated.
  • The decimal point in the output is necessary. If you choose to output via return value, you must return a floating point integer.
  • The goal of this challenge is to find the shortest solution in each language, not the shortest language for the solution. Don't be afraid to post a solution in a language when a shorter solution is posted in the same language as long as your solution uses a different method.
  • \$\begingroup\$ ...so would this be valid or not? \$\endgroup\$ – Jonathan Allan Sep 15 '17 at 16:59
  • \$\begingroup\$ (edit ^ this even (rounding)) \$\endgroup\$ – Jonathan Allan Sep 15 '17 at 17:07
  • \$\begingroup\$ “Code length” ← in bytes or in characters? \$\endgroup\$ – Lynn Sep 17 '17 at 21:19
  • \$\begingroup\$ @Lynn Bytes, as usual. \$\endgroup\$ – MD XF Sep 17 '17 at 23:50
  • \$\begingroup\$ Is just 3 allowed? \$\endgroup\$ – NoOneIsHere Apr 23 '18 at 21:47

32 Answers 32


Perl 6, 16 bytes

{4*atan       1}

Try it online!

  • 1
    \$\begingroup\$ 13 bytes using tau \$\endgroup\$ – Jo King Apr 16 at 6:13

Brainfuck (32 bit), 672 660 bytes


All credit should go to Felix Nawothnig's yapi.b.

Should you decide to downvote, please leave a comment explaining why.

  • \$\begingroup\$ @JoKing Thanks for your feedback. To get the correct amount of digits you have to use 32 bit cells as specified in the title (160 = 672 mod 256). I have now also added a link to the source. \$\endgroup\$ – orthoplex Apr 16 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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