Bake a slice of Pi

82

10

Write a program or function that prints or outputs this exact text (consisting of 142 characters):

()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|

Your program must take no input (except in languages where this is impossible, such as sed), and produce the above text (and only the above text) as output. A trailing newline is acceptable.

This is , so the shortest answer (in bytes) wins.

Copper

Posted 2016-09-17T10:09:59.523

Reputation: 3 684

This seems to be overly complex in the kolmogorov sense. I will be impressed if anyone can compress this – Rohan Jhunjhunwala – 2016-09-17T10:44:32.177

9

@RohanJhunjhunwala For proof that this can be compressed, Luis Mendo did it.

– Erik the Outgolfer – 2016-09-17T13:42:06.220

1Lol, I have been proven wrong (and I am glad!) very impressive – Rohan Jhunjhunwala – 2016-09-17T15:40:40.293

2You cold have made them take an integer input N to output a slice whose number of () at the top is N. It would be very complex tho. – user6245072 – 2016-09-17T17:02:19.223

5Just so you know, you need 43 decimal places of π. – Erik the Outgolfer – 2016-09-17T18:36:23.357

4So close to the meaning of life.... – A. Mirabeau – 2016-09-20T04:04:52.817

Answers

90

MATL, 70 68 67 bytes

'()'12:)l10:&<toYP43Y$51hb(!10Xy'\::\'FFhZ++'|'3$Yc'||\'3:(95'Zd'o(

Try it online!

Explanation

What a mess. But hey, there's a convolution!

The explanation will be clearer if you can inspect the stack contents after a given statement. To do it, just insert X#0$% at that point. (This means: X# show stack contents, 0$ don't implicitly display anything else, % comment out rest of the code). For example, see the stack right after the convolution.

'()'       % Push this string
12:        % Range [1 2 ... 12]
)          % Index into string (modular, 1-based): gives '()()()()()()'
l          % Push 1 (will be used later)
10:        % Range [1 2 ... 10]
&<         % All pairwise "less than" comparisons. Gives matrix with "true"
           % below the main diagonal, and the remining entries equal to "false"
to         % Duplicate. Convert to numbers (true becomes 1, false becomes 0)
YP43Y$     % Compute pi with 43 significant digits (42 decimals). Gives a string
51h        % Append last decimal, '3' (ASCII 51). This is needed to avoid rounding
b          % Bubble up the true-false matrix, to be used as logical index
(          % Fill the chars from the pi string into the 0-1 matrix, at the positions
           % indicated by the true-false matrix. Thus each 1 is replaced by a char
           % from the pi string. Entries that were 0 remain as 0. This is done in
           % columm-major order...
!          % ...so transpose to make it row-major
10Xy       % Identity matrix of size 10
'\::\'     % Push this string...
FFh        % ...and append two zeros
Z+         % 2D convolution keeping size. The identity matrix convolved with the
           % above string gives the diagonal bands with chars '\'  and ':'
+          % Add to the matrix containing the digits of pi. At each entry, only one
           % of the two matrices is nonzero
'|'        % Push this string
3$Yc       % Three-input string concatenation. This prepends the 1 (which was pushed
           % a while ago) and appends '|' to each row of the matrix. This converts
           % the matrix to char. Note that char 1 will be displayed as a space. We
           % used char 1 and not char 0 (which would be displayed as a space too)
           % because function `Yc` (`strcat`) strips  off trailing space from the
           % inputs, counting char 0 as space, but not char 1
'||\'      % Push this string
3:(        % Assign it to the first 3 entries of the matrix (column-major), that is, 
           % to the top of the first column
95         % Push ASCII for '_'
'Zd'o      % Push string 'Zd' and convert to numbers: gives [90 100]. These are the
           % (column-major) indices where the '_' char should appear in the last row
(          % Fill those chars
           % Implicitly display. (Chars 0 and 1 are displayed as space)

Luis Mendo

Posted 2016-09-17T10:09:59.523

Reputation: 87 464

14Luis Mendo, this is impressive. I would upvote twice if I could. I thought this would be an incompressible kolmogorov challenge. Thank you for proving me wrong! – Rohan Jhunjhunwala – 2016-09-17T15:42:43.777

3@Rohan Thanks for your kind words! – Luis Mendo – 2016-09-17T16:59:16.580

1:D No problem! :D – Rohan Jhunjhunwala – 2016-09-17T17:16:10.293

3+1 for the :) that appears in your code. – Erik the Outgolfer – 2016-09-18T09:03:25.787

What would happen if you calculated the first 47 digits of π instead? – Neil – 2016-09-19T08:44:14.587

@Neil Thanks! That's what I initially did, but removing the last two digits took more bytes than adding a final three – Luis Mendo – 2016-09-19T09:50:04.420

1@EriktheGolfer But there's also a :(... – Neil – 2016-09-19T12:01:42.570

2@Neil See the bright side of life... – Erik the Outgolfer – 2016-09-19T12:03:29.913

There's also a :/ with a backslash. – HyperNeutrino – 2017-03-09T13:17:50.903

37

Perl, 93 bytes

$_=bpi$=;printf'()'x6x!$`.'
%12s',F.ee x!$\--^substr"\32::\\$&|",-12while/.{$\}/g

Requires the command line option -l71Mbignum=bpi, counted as 14. The \32 should be replaced by a literal character 26.

Sample Usage

$ perl -l71Mbignum=bpi pi-slice.pl
()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|

Perl, 111 bytes

$_=bpi$_*($l=($.=$_)-3);printf'()'x($./2)x!$`."
%$.s",F.ee x!$l--^substr"\32::\\$&|",-$.while/.{$l}/g

Parameterized version. Requires the command line option -nMbignum=bpi, counted as 12.

Sample Usage

$ echo 10 | perl -nMbignum=bpi pi-slice.pl
()()()()()
|\3.14159|
|:\265358|
\::\97932|
 \::\3846|
  \::\264|
   \::\33|
    \::\8|
     \__\|

$ echo 20 | perl -nMbignum=bpi pi-slice.pl
()()()()()()()()()()
|\3.141592653589793|
|:\2384626433832795|
\::\028841971693993|
 \::\75105820974944|
  \::\5923078164062|
   \::\862089986280|
    \::\34825342117|
     \::\0679821480|
      \::\865132823|
       \::\06647093|
        \::\8446095|
         \::\505822|
          \::\31725|
           \::\3594|
            \::\081|
             \::\28|
              \::\4|
               \__\|

primo

Posted 2016-09-17T10:09:59.523

Reputation: 30 891

25

JavaScript (ES6), 187 174 bytes

This is 1 byte shorter than just displaying the plain text.

for(y=n=0,s=`()()()()()()
`;y<10;y++,s+=`|
`)for(x=-2;x++<9;)s+=x>y?(Math.PI+'2384626433832795028841971693')[n++]:`\\${y>8?'__':x+1|y>2?'::':'||'}\\`[y-x]||' ';console.log(s)

Arnauld

Posted 2016-09-17T10:09:59.523

Reputation: 111 334

1Isn´t it one byte shorter than console.log("") + 12*11 characters + 18 backslashes + 10 linebreaks? – Titus – 2016-09-17T14:28:51.483

@Titus - You're right. I forgot to count backslash escaping. Thanks! – Arnauld – 2016-09-17T15:03:59.993

18Mildly interesting, but 2384626433832795028841971693 happens to be prime. – ElementW – 2016-09-17T17:18:04.440

1@ElementW - Funny that you mentioned it, because I did check that too. :) – Arnauld – 2016-09-17T17:18:49.410

Would writing the number as hex and converting it to a string save any bytes? – Fund Monica's Lawsuit – 2016-09-19T18:20:17.300

@ElementW What about close numbers? You could multiply or exponentiate to get a close number, then add the difference. – mbomb007 – 2016-09-19T18:24:29.090

@QPaysTaxes - This number is 91-bit long, which is far beyond JS capacity. It could not be converted from/to hexadecimal in a single pass. – Arnauld – 2016-09-19T18:29:19.183

@Arnauld Yeah, I just figured that out. You can't represent numbers larger than 2**53 as a literal. – mbomb007 – 2016-09-19T18:31:45.467

@Arnauld Ah, I underestimated the size. Thanks for the explanation. – Fund Monica's Lawsuit – 2016-09-19T18:53:14.027

Math.PI+'238462643383'+0x9ee105d433fed is sadly no better than Math.PI+'2384626433832795028841971693', and collapsing more digits in drops precision – Eric – 2016-09-19T21:30:37.910

17

Python 2, 131 bytes

print'()'*6+'\n|\\3.1415926|\n|:\\53589793|'
for n in 2384626,433832,79502,8841,971,69,3,'':print'%11s|'%('\%s'*2%('_:'[n<'']*2,n))

Joint effort between Sp3000 and Lynn. Copper saved a byte, too! Ideone link.

Lynn

Posted 2016-09-17T10:09:59.523

Reputation: 55 648

That's elegant +1 – ElPedro – 2016-09-18T12:43:15.277

You should be able to save 1 byte by removing the brackets in the for loop. – Copper – 2016-09-18T12:51:08.117

16

///, 129 127 bytes

/-/\\\\//&/--::--//%/  //#/|
%//!/()()/!!!
|-3.1415926|
|:-53589793|
&2384626|
 &433832#&79502# &8841#%&971#% &69#%%&3#%% -__-|

Try it online!

Erik the Outgolfer

Posted 2016-09-17T10:09:59.523

Reputation: 38 134

-2 bytes if you do /!/()()/!!! instead of ()()()()()() and replace /#/|\n%%/ with /#/|\n%/ and adjust the rest of the code to make it work with that. – acrolith – 2016-09-17T18:10:49.760

@daHugLenny Oh thanks, I didn't know 4 * 3 was a valid candidate for replacement. For your second suggestion, I think it will be longer. – Erik the Outgolfer – 2016-09-17T18:25:26.850

@daHugLenny ^^ I can confirm that your second suggestion is indeed longer. – Erik the Outgolfer – 2016-09-17T18:33:31.313

It isn't, I got 127 bytes with it. – acrolith – 2016-09-17T18:36:41.480

@DestructibleWatermelon I did it intentionally. There are also other faces: -:, :-, :- and -__-. – Erik the Outgolfer – 2016-09-18T08:49:23.437

12

Bash, 153 bytes

cat << _
()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|
_

Chris

Posted 2016-09-17T10:09:59.523

Reputation: 161

9

Considering how many of the other answers fell into the trap of producing code longer than printing the literal pie, I think this is a smart answer indeed. Also, it’s only 153 bytes by my count.

– Lynn – 2016-09-18T12:39:18.587

3@Lynn However, it is just dumping the example to the output with no attempt of golfing, and so is discouraged. At least the other answers made an effort... – Beta Decay – 2016-09-18T12:58:50.860

You can remove the spaces before and after the <<. And your bytecount is of 153 bytes. – TuxCrafting – 2016-09-18T13:12:12.927

1Isn't echo '()()()()()()...\__\|' 4 bytes shorter? – Neil – 2016-09-19T08:49:33.587

@Lynn I'm glad I didn't have that problem; Batch requires 100 bytes of overhead to simply print the pie. – Neil – 2016-09-19T08:53:06.450

@DJMcMayhem I think it's a valid golf, seeing as most answers are longer than this. – None – 2016-09-19T15:06:59.113

Arguably you could call cat your interpreter at this point, and make your source code be literally the output – Eric – 2016-09-19T21:40:50.343

9

Batch, 195 bytes

@echo ()()()()()()
@echo ^|\3.1415926^|
@echo ^|:\53589793^|
@set i=\
@for %%d in (2384626 433832 79502 8841 971 69 3)do @call:l %%d
@echo %i%__\^|
@exit/b
:l
@set i= %i%
@echo%i%::\%1^|

Neil

Posted 2016-09-17T10:09:59.523

Reputation: 95 035

5

Turtlèd, 135 129 bytes (not competing)

(the interpreter isn't really slightly buggèd (anymore :]), but it does not affect this program)

By restructuring and rewriting my program, I golfed... six bytes

And now I have to make new explanation...

Still could be shorter probs though


At least the best solution in this lang isn't just writing in the raw data ¯\_(ツ)_/¯


#3.141592653589793238462643383279502884197169#")()()()()()">10:[)'|l]:[)d'\l]d"(||"2uuu[|;"::"uuu];>"__"[|r'\d]dl[ l[|.+l][\r]ul]

Try it online

Explanation

Honestly, this doesn't describe the actual program very well, but it does give hints about the commands, so you might understand a little better

#3.141592653589793238462643383279502884197169# Some pi. Set the string to thing between #s
                                               the last digit was same as first, and the
                                               string wraps, so digit could be removed
")()()()()()"  Write this string, by writing char 1 to current cell, moving right, char 2...

>              turn right

10             set register to ten

:[)'|l]:       move right by amount in register, while current cell isn't ), write |
               and move left. move right by amount in register

[)d'\l]        while cell is not (, move down, write \, move left

d"(||"         move down and string-write "(||"

2              set register to 2

uuu[|;"::"uuu] Move up three, and while the cell is not |, move down by
               register (2), string-write "::", move up three

               Just remember the turtle is currently pointing right, so up is right.

;>"__"         move down by amount in register, turn right, string-write "__"

[|r'\d]dl      while cell is not |{ move right, write \, move down}, move down, left

COMPLEX THING: NESTED LOOPS

[ l[|.+l][\r]ul]

While the current cell is not space {move left, execute loop:(While cell not |, write current char of string variable (remember that pi?), increment string pointer, move left), execute loop:(while cell not \, move right), move up, left}

Destructible Lemon

Posted 2016-09-17T10:09:59.523

Reputation: 5 908

Why non-competing? – programmer5000 – 2017-04-19T17:46:34.710

not competing means it is newer than the challenge – Destructible Lemon – 2017-04-20T00:33:16.690

5

Fourier, 196 190 bytes

New feature alert!

Code

|SaCaaSa|f|~Y0~jY(32aj^~j)|w6(40a41ai^~i)10a~N124a~W92a~S3o46a1415926oWaNaWa58a~CSa53589793oWaNaf2384626oWaNa1wf433832oWaNa2wf79502oWaNa3wf8841oWaNa4wf971oWaNa5wf69oWaNa6wf3oWaNa7wSa95aaSaWa

Explanation

This program is my first demonstration of functions in Fourier:

Functions are defined like so:

|code goes here|f

The first pipe starts the function declaration. You then put the code in between the pipes. The last pipe ends the function declaration. Finally, the f is the variable in which the function is stored. This can be any character, as long as it isn't a reserved function.

For example, in my code, one of the function s is:

|SaCaaSa|f

Where the variable S stores the number 92 and C stores the number 58.

When called, the function outputs the following:

\::\

Since it is the most repeated thing in the pie.

Similarly, to golf down the output, I have used a loop:

6(40a41ai^~i)

Which repeats the code 40a41a 6 times. 40a41a on its own outputs:

()

So repeating the code six times outputs:

()()()()()()

Thereby outputting the crust of the pie.

Try it on FourIDE!

Because I haven't implemented functions in the Python interpreter, this program will not work on http://tryitonline.net

Beta Decay

Posted 2016-09-17T10:09:59.523

Reputation: 21 478

4

Pyth, 89 bytes

J_2K+.n0."09\07´\C2\84J\01£\07Nl:?í"*"()"6Vr9Zp*dJp?!Z\|?qZ9"|:""\::"p\\p:KZ+ZN\|=+ZN=hJ)p*dJ"\__\|"

Try it online!

Replace \xx (hexadecimal) with the corresponding ASCII character if you copy/paste the code from this answer; it contains unprintable characters in the packed string which SE filters out.

Explanation

J_2        Sets J to -2
  .n0      Pi; returns 3.141592653589793
  ."(...)" Packed string; returns "2384626433832795028841971693"
 +         Concatenation; returns "3.1415926535897932384626433832795028841971693"
K          Sets K to that string
*"()"6     Repetition; returns "()()()()()()", which is implicitly printed with a newline
 r9Z       Range; returns [9, 8, 7, 6, 5, 4, 3, 2, 1] (Z is initialized to 0)
V          Loop through r9Z, using N as the loop variable
  *dJ      Repetition; d is initialized to " " (returns an empty string if J <= 0)
 p         Print without a newline
  ?!Z      Ternary; if not Z
   \|      then return "|"
   ?qZ9    else, ternary; if Z == 9
    "|:"   then return "|:"
    "\::"  else, return "\::"
 p         Print without a newline
  \\       One-character string; returns "\"
 p         Print without a newline
  :KZ+ZN   Slice; returns K[Z:Z+N], not including K[Z+N]
 p         Print without a newline
 \|        One-character string; returns "|", which is implicitly printed with a newline.
 =+ZN      Adds N to Z
 =hJ       Increments J by 1
)          Ends loop
 *dJ       Repetition; d is initialized to " "
p          Print without a newline
"\__\|"    Returns "\__\|", which is implicitly printed with a newline

insert_name_here

Posted 2016-09-17T10:09:59.523

Reputation: 816

4

Jelly, 83 bytes

surely still quite golfabale

7Ḷ⁶ẋ;€“\::\”“|:\”ṭṙ7
⁾()ẋ6⁷⁾|\8ØPæp”|⁷8RUR€µ“⁾ḅ|Za"~ṅỵþȷ^ṇ⁷Ċ’Dṁ;€”|ż@¢Y⁷ø⁶ẋ7“\__\|”

TryItOnline

How?

7Ḷ⁶ẋ;€“\::\”“|:\”ṭṙ7 - Link 1, left side padding and filling
7Ḷ                   - lowered range of 7 ([0,1,2,3,4,5,6])
      “\::\”         - filling ("\::\")
  ⁶ẋ;€               - space character repeated that many times and concatenate for each
            “|:\”    - top crust edge filling ("|:\")
                 ṭ   - tack (append to the end)
                  ṙ7 - rotate to the left by 7 (move top crust filling to the top)

⁾()ẋ6⁷⁾|\8ØPæp”|⁷8RUR€µ - Main Link (divided into two for formatting)
⁾()ẋ6⁷                  - "()" repeated 6 times and a line feed
      ⁾|\               - "|\"
          ØP            - pi
         8  æp          - round to 8 significant figures (top edge of the glaze)
              ”|⁷       - "|" and a line feed
                 8R     - range of 8 ([1,2,3,4,5,6,7,8])
                   U    - reverse ([8,7,6,5,4,3,2,1])
                    R€  - range for each ([[1,2,..8],[1,2,..7],...,[1,2],[1]])
                      µ - monadic chain separation

“⁾ḅ|Za"~ṅỵþȷ^ṇ⁷Ċ’Dṁ;€”|ż@¢Y⁷ø⁶ẋ7“\__\|” - Main link (continued)
“⁾ḅ|Za"~ṅỵþȷ^ṇ⁷Ċ’                       - base 250 representation of the rest of the digits
                 D                      - decimalise (makes it a list)
                  ṁ                     - mould (into the shape of the array formed above)
                     ”|                 - "|"
                   ;€                   - concatenate for each
                         ¢              - call last link (1) as a nilad
                       ż@               - zip (with reversed operands)
                          Y⁷            - join with line feeds, and another line feed
                            ø           - niladic chain separation
                             ⁶ẋ7        - space character repeated 7 times
                                “\__\|” - "\__\|" the very bottom of the pie wedge

Jonathan Allan

Posted 2016-09-17T10:09:59.523

Reputation: 67 804

2Wow, that's the longest Jelly program I've ever seen :o – Beta Decay – 2016-09-22T06:34:40.907

@BetaDecay no doubt it can be done in 11 bytes... – Jonathan Allan – 2016-09-22T07:20:05.293

3

Charcoal, 31 bytes

×⁶()↙↓¹⁰↖↖¹⁰↓↓²↘⁸M↑__↖←¤:↗¤UGPi

Try it online!

You may be wondering: what is this sorcery? How can you fill with UGPi? Well, Charcoal is starting to get Wolfram Language support, in the hope that one day it can be competitive in more challenges!

Previous, 71 bytes

×⁶()↙↓¹⁰↖↖¹⁰↓↓²↘⁸M↑__↖←¤:↗¤3.141592653589793238462643383279502884197169

Try it online!

Verbose

Print(Multiply(6, "()"));
Move(:DownLeft)
Print(:Down, 10)
Move(:UpLeft)
Print(:UpLeft, 10)
Move(:Down)
Print(:Down, 2)
Print(:DownRight, 8)
Move(:Up)
Print("__")
Move(:UpLeft)
Move(:Left)
Fill(":")
Move(:UpRight)
Fill("3.141592653589793238462643383279502884197169")

Note that this is different as the deverbosifier automatically compresses strings and does not remove redundant commands.

With compressed strings, 52 bytes

×⁶¦()↙↓¹⁰↖↖¹⁰↓↓²↘⁸↑__↖←¤:M↗¤”i¶∧²uτ¶R›    §Q´⌈#_⮌POÞ”

xxd output

0000000: aab6 ba28 291f 14b1 b01c 1cb1 b014 14b2  ...()...........
0000010: 1eb8 125f 5f1c 11ef 3acd 1def 0469 0a01  ...__...:....i..
0000020: b275 f40a 52be 0999 9fa4 d1e0 1a23 5f86  .u..R........#_.
0000030: d04f de04                                .O..

Try it online!

ASCII-only

Posted 2016-09-17T10:09:59.523

Reputation: 4 687

3

PowerShell, 105 bytes

'()'*6
'|\3.1415926|
|:\53589793|'
2384626,433832,79502,8841,971,69,3|%{" "*$i+++"\::\$_|"}
' '*7+'\__\|'

Try it online!

Not sure how I never answered this challenge ... I upvoted it and several of the other answers. Oh well, better late than never?

This puts six balanced parens as a string on the pipeline, then a literal string (saves two bytes) of the next two rows. Then, we loop through the rest of the numbers, each iteration incrementing the number of prepended spaces ($i) concatenated with \::<number>|. Finally, we create a string of the tip of the pie. Those strings are all left on the pipeline, and an implicit Write-Output sticks a newline between.

This is 39 bytes shorter than just printing the pie.

AdmBorkBork

Posted 2016-09-17T10:09:59.523

Reputation: 41 581

3

Python 2, 193 176 bytes

P="3.1415926 53589793 2384626 433832 79502 8841 971 69 3".split()
f="()"*6+"\n|\%s|\n|:\%s|\n"%(P[0],P[1])
for s in range(7):f+=" "*s+"\::\\"+P[s+2]+"|\n"
print f+" "*7+"\__\|"

Or a shorter, more boring answer:

print r"""()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|"""

acrolith

Posted 2016-09-17T10:09:59.523

Reputation: 3 728

3Are you aware that print r'''(the pie)''' is 38 bytes shorter? :) – Lynn – 2016-09-18T12:19:11.450

+1 for your second effort but using single quotes makes it shorter to look at. Pixel count is better :) – ElPedro – 2016-09-19T17:44:48.913

3

C# 220 213 209 208 202 201 (171*) Bytes

*I find this to be unoriginal and cheating

void F()=>Console.Write(@"()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|");

201 Bytes:

void f(){var s="()()()()()()\n";for(int i=0;i<9;)s+=(i<1?"|":i<2?"|:":"\\::".PadLeft(i+1))+$"\\{new[]{3.1415926,53589793,2384626,433832,79502,8841,971,69,3}[i++]}|\n";Console.Write(s+@"       \__\|");}

220 bytes:

I'm sure that there is something to be golfed here

void f(){string s="()()()()()()\n",x="       ";for(int i=9,j=0;i>0;j+=i--)s+=(i>7?"|"+(i<9?":":"")+"\\":x.Substring(i)+@"\::\")+$"{Math.PI}32384626433832795028841971693".Substring(j,i)+"|\n";Console.Write(s+x+@"\__\|");}

pinkfloydx33

Posted 2016-09-17T10:09:59.523

Reputation: 308

Thanks for the answer! You can save a least one byte by removing the extra space in .Substring(j, i). – Copper – 2016-09-18T10:55:37.903

That was an oversight from auto-formatting in VS, but I saved a bunch a different way anyhow =) – pinkfloydx33 – 2016-09-18T11:06:20.913

An anonymous function returning the pie verbatim is >25% shorter: ()=>@"(pie)" is 149 bytes.

– Lynn – 2016-09-18T17:17:23.700

It's also boring and feels like cheating. Rules say to print, not return – pinkfloydx33 – 2016-09-18T17:22:29.117

@pinkfloydx33 Printing and returning are both allowed by default according to community consensus.

– mbomb007 – 2016-09-19T18:39:10.097

That's what I thought but the wording and the fact a lot of the other answers (that I understand) use some form of print/echo unless it'd simply because they are shorter than return – pinkfloydx33 – 2016-09-19T20:21:28.087

2

Stax, 63 bytes

ü?½Pi<Θ*q}ü¿▒5Ç>cdƒ±<Gw►,─ô╟▒g•iâÑ♠514Φ⌂!Ñεùáèè♂ÑD╔«dÿ47¡ô#UV•╧

Run and debug online!

Shorter than the accepted MATL answer. It would definitely be shorter if more digits were stored as the constant pi in Stax.

(What is that Pi<0 in the code?)

Explanation

Uses the ASCII equivalent to explain, which is

.()6*PVP$2ME.|\a+"|:\"a+"!RNyb2L$-!mV=223w+&O-"!{"\::\"s$+mELr"\__\"]+|>m'|+

Expalantion:

.()6*PVP$2ME.|\a+"|:\"a+
.()                           "()"
   6*P                        Print 6 times
      VP$                     First two lines of pi in the output
         2ME                  Push the two lines separately on the stack
            .|\a+             Prepend the first line with "|\"
                 "|:\"a+      Prepend the second line with "|:\"

"..."!{"\::\"s$+mELr"\__\"]+|>m'|+
"..."!                                [2384626,433832,79502,8841,971,69,3]
      {"\::\"s$+m                     Convert each element to a string and prepend "\::\"
                 ELr                  Prepend the first two lines to array
                    "\__\"]+          Append "\__\" to the converted array
                            |>        Right align text
                              m'|+    Append "|" to each array element and print

Weijun Zhou

Posted 2016-09-17T10:09:59.523

Reputation: 3 396

2

PHP, 170 bytes

no arbritrary precision Pi in PHP? Calculating takes much more space than Copy&Paste. Doesn´t matter that the last digit here is cut, not rounded; but in 64 bit Pi the last digit gets rounded up.

for(;$i<11;)echo str_pad($i?["\\__\\","|\\","|:\\","\\::\\"][$i>9?0:min(3,$i)].[3.1415926,53589793,2384626,433832,79502,8841,971,69,3][$i-1]."|
":"
",13,$i++?" ":"()",0);

Run with php -r '<code>'

uncommented breakdown

for(;$i<11;)
    echo str_pad($i?
         ["\\__\\","|\\","|:\\","\\::\\"][$i>9?0:min(3,$i)]
        .[3.1415926,53589793,2384626,433832,79502,8841,971,69,3][$i-1]
        ."|\n"
    :"\n"
    ,13,$i++?" ":"()",0);

Titus

Posted 2016-09-17T10:09:59.523

Reputation: 13 814

The output is missing 1 space (which you can fix by changing that 13 with a 14). And, for some bizarre reason, You are missing the closing parenthesis at the top. Making the change fixes the output. – Ismael Miguel – 2016-09-18T12:12:08.343

PHP answers need a <?php tag, otherwise they just produce constant output. PHP Hello, World! actually depends on this. However, speaking of constant output, a PHP answer that just contains the literal cake and no <?php tag at all would beat yours by a big margin…

– Lynn – 2016-09-18T12:28:06.320

@Lynn: PHP does not need the <?php tag when you run it with -r. – Titus – 2016-09-18T12:39:32.113

2

Python 2, 183 171 bytes

p,d=[2384626,433832,79502,8841,971,69,3],"|\n"
c=("()"*6)+d[1]+"|\\"+`3.1415926`+d+"|:\\"+`53589793`+d
for x in range(7):c+=" "*x+"\\::\\"+`p[x]`+d
print c+" "*7+"\\__\\|"

Does't really do anything clever. Just builds up a big string then prints it out.

EDIT

Reduced to 171 after reading @Lynn's answer and learning. Sorry if it is wrong to (shamelessly) steal some bytes from you without you suggesting it. Please tell me if so and I will roll back the change.

Output

python pi.pie.py

()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|

ElPedro

Posted 2016-09-17T10:09:59.523

Reputation: 5 301

Are you aware that print r'''(the pie)''' is 28 bytes shorter? :) – Lynn – 2016-09-18T12:18:15.893

@Lynn Is that not cheating? ;-) – ElPedro – 2016-09-18T12:21:54.707

It's not cheating, just not very interesting (and we don't need that answer for every language, IMO. The bash answer is sufficient). More like something you'd want to mention when posting an answer like this, to acknowledge that your golfing attempt ended up being a loss. Maybe still worth posting in case someone else sees a way to take your golfing idea and improve on it, maybe beating the naive approach. – Peter Cordes – 2016-09-19T16:48:00.753

I take your comments on board @Peter. i was not trying to be disrespectful hence the smiley. Anyone can just print out an ASCII art challenge like this. I'm pretty new to this and am here to learn. If it means anything I did put a comment and a +1 on Lynn's answer when I saw that it was not just a print statement but addressed the issue in a way that totally outclassed my effort. I have learned... – ElPedro – 2016-09-19T17:09:15.457

As long as your answer still has a different approach, it's fine to get ideas from other answers (in the same language or not). The only thing that would be not ok is if your answer ended up with exactly the same code as Lynn's. Usually if you see a small improvement to someone else's answer, you'd suggest that in a comment. But if you have multiple new ideas after seeing someone else's answer, you can even post your improved version as a new answer. I'm not totally sure about the etiquette of this, but I think it's fine as long as your answer is significantly different. – Peter Cordes – 2016-09-19T17:46:33.210

My answer is significantly worse than Lynn's so I hope there are no objections :) – ElPedro – 2016-09-19T17:51:35.053

2

Ruby, 140 138 137 bytes

My solution to this problem in ruby, this is my first code golf answer :D

[0,2384626,433832,79502,8841,971,69,3,1].map{|n|puts n<1?"()"*6+"\n|\\3.1415926|\n|:\\53589793|":"\\#{n>1?"::\\#{n}":"__\\"}|".rjust(12)}

Readable version and explanation:

for n in [-1,2384626,433832,79502,8841,971,69,3,0]
  if n < 0 # n == -1
    puts "()"*6+"\n|\\3.1415926|\n|:\\53589793|"
  else
    if n > 0 # digits of pi
      puts "\\::\\#{n}|".rjust(12)
    else # edge of pie
      puts "\\__\\|".rjust(12) 
    end
  end
end

Nothing really clever, just using some simple loops :)

Output:

()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|

Linus

Posted 2016-09-17T10:09:59.523

Reputation: 141

2Welcome to PPCG! Nice first post! – Rɪᴋᴇʀ – 2016-09-21T10:51:04.293

1

Java 7, 260 236 191 bytes

String d(){return"()()()()()()\n|\\3.1415926|\n|:\\53589793|\n\\::\\2384626|\n \\::\\433832|\n  \\::\\79502|\n   \\::\\8841|\n    \\::\\971|\n     \\::\\69|\n      \\::\\3|\n       \\__\\|";}

Sigh, simply outputting the pie is shorter, even with all the escaped backslashes.. >.>
Here is previous answer with a tiny bit of afford, although still not very generic or fancy (236 bytes):

String c(){String n="\n",p="|",q=p+n,x="\\::\\",s=" ",z=s;return"()()()()()()"+n+p+"\\"+3.1415926+q+p+":\\53589793"+q+x+2384626+q+s+x+433832+q+(z+=s)+x+79502+q+(z+=s)+x+8841+q+(z+=s)+x+971+q+(z+=s)+x+69+q+(z+=s)+x+3+q+(z+=s)+"\\__\\|";}

A pretty boring answer, since simply outputting the result without too much fancy things is shorter in Java than a generic approach.

Ungolfed & test code:

Try it here.

class M{
  static String c(){
    String n = "\n",
           p = "|",
           q = p + n,
           x = "\\::\\",
           s = " ",
           z = s;
    return "()()()()()()" + n + p + "\\" + 3.1415926 + q + p + ":\\53589793" + q + x + 2384626 + q + s
            + x + 433832 + q + (z += s) + x + 79502 + q + (z += s) + x + 8841 + q 
            + (z += s) + x + 971 + q + (z += s) + x + 69 + q + (z += s) + x + 3 + q
            + (z += s) + "\\__\\|";
  }

  public static void main(String[] a){
    System.out.println(c());
  }
}

Output:

()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|

Kevin Cruijssen

Posted 2016-09-17T10:09:59.523

Reputation: 67 575

1

Qbasic, 175 bytes

?"()()()()()()":?"|\3.1415926|":?"|:\53589793|":?"\::\2384626|":?" \::\433832|":?"  \::\79502|":?"   \::\8841|":?"    \::\971|":?"     \::\69|":?"      \::\3|":?"       \__\|"

anonymous2

Posted 2016-09-17T10:09:59.523

Reputation: 421

1

Lua, 152 Bytes

print[[()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|]]

Try as I might I could not compress this pi.

Lua is just too verbose to do it, maybe a pi of greater size, but not this one.

Another solution, 186 Bytes.

s="()()()()()()\n|\\3.1415926|\n|:\\53589793|\n"i=0 for z in('2384626|433832|79502|8841|971|69|3|'):gmatch'.-|'do s=s..(' '):rep(i)..'\\::\\'..z.."\n"i=i+1 end print(s..'       \\__\\|')

Annoyingly Lua's pi isn't accurate enough to even fill the pi. :(

ATaco

Posted 2016-09-17T10:09:59.523

Reputation: 7 898

1

JavaScript (ES6), 170 bytes 165 bytes

is a bit "cheated", since if run on the console, the return value would be displayed

v=0;("()()()()()()\n|9|:87654321".replace(/\d/g,(o)=>"\\"+(Math.PI+'2384626433832795028841971693').substr(v,o,v-=-o)+"|\n"+(o<9?" ".repeat(8-o)+(o>1?"\\::":"\\__\\|"):""))

After some teaking, the function looks like this(function must be called with parameter with the value 0):

v=>`()()()()()()
 |9 |:87654321\\__\\|`.replace(/\d/g,o=>`\\${(Math.PI+"2384626433832795028841971693").substr(v,o,v-=-o)}|
${" ".repeat(9-o)+(o<9&o>1?"\\::":"")}`)

If you want to call the function 167 bytes:

z=v=>`()()()()()()
 |9 |:87654321\\__\\|`.replace(/\d/g,o=>`\\${(Math.PI+"2384626433832795028841971693").substr(v,o,v-=-o)}|
${" ".repeat(9-o)+(o<9&o>1?"\\::":"")}`)


/*could be run like this or directly in the console*/
console.info("\n"+z(0));

winner_joiner

Posted 2016-09-17T10:09:59.523

Reputation: 111

1: Needs extra closing paren. 2: replace "|\n" with |<newline> where <newline> is a literal newline. 3: Add y=> to the beginning and it won't be cheating. 4: Welcome to the site! – programmer5000 – 2017-04-19T17:55:09.953

1@programmer5000 thanks for your input, I used it on my latest tweak. :-D – winner_joiner – 2017-04-20T11:40:03.163

Save 2 bytes by removing the () enclosing the v parameter. Your output seems to have an extra space in front of the 2nd & 3rd lines. Also, you don't need to pass 0 as an argument, your function will work fine without it and it's also not permitted by the challenge. – Shaggy – 2017-04-20T11:54:13.097

yes thank you, I had before default value. :-D – winner_joiner – 2017-04-20T12:23:14.210

1

Javascript, 172 bytes

Paste into your console to run.

for(y=n=0,s=`()()()()()()
`;y<10;y++,s+=`|
`)for(x=-2;x++<9;)s+=x>y(Math.PI+'2384626433832795028841971693'[n++]:`\\${y>8?'__':x+1|y>1?'::':'||'}\\`[y-x]||' ';console.log(s)

Kajal Chaudhari

Posted 2016-09-17T10:09:59.523

Reputation: 11

Welcome to PPCG! Just so you know, you can format your code with four spaces (see my edit). Also, put the amount of bytes in your program at the top of your answer (e.g. Javascript: 100 bytes). – clismique – 2016-09-21T10:31:57.993

Seems to have weird syntax errors, can you fix those? – programmer5000 – 2017-04-19T17:58:22.817

0

PHP, 142 bytes

Sneaky-sneaky :) php just prints everything out without trying to interpret them as PHP code if it does not see any <?php ?> pairs.

()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|

iBug

Posted 2016-09-17T10:09:59.523

Reputation: 2 477