4
\$\begingroup\$

There is an asdfmovie video about a pie flavoured pie. Someone also made an edited version with more pies, so I created this challenge.

The input is a positive integer.

The code should first output the following string:

I baked you a pie!
Oh boy, what flavour?

Then, the next line should be PIE (input number of times) + flavour..

Next, print a blank line.

After that, ASCII-art pies should be drawn.

Here is what a size-1 pie looks like.

 _________
/         \
-----------
 \       /
  -------

Size-2 pie:

 _____________
/             \
---------------
 \           /
  -----------

Size-3 pie:

 _________________
/                 \
-------------------
 \               /
  ---------------

Each pie starting from size-2 should be four characters longer on each line than the pie one smaller.

The program should draw (input number + 1) pies, seperated by newlines, with increasing sizes (1 at the top, 2 directly below it, etc).

The pies should be centred.

Examples:

Input 1

I baked you a pie!
Oh boy, what flavour?
PIE flavour.

   _________
  /         \
  -----------
   \       /
    -------
 _____________
/             \
---------------
 \           /
  -----------

Input 2

I baked you a pie!
Oh boy, what flavour?
PIE PIE flavour.

     _________
    /         \
    -----------
     \       /
      -------
   _____________
  /             \
  ---------------
   \           /
    -----------
 _________________
/                 \
-------------------
 \               /
  ---------------

Input 3

I baked you a pie!
Oh boy, what flavour?
PIE PIE PIE flavour.

       _________
      /         \
      -----------
       \       /
        -------
     _____________
    /             \
    ---------------
     \           /
      -----------
   _________________
  /                 \
  -------------------
   \               /
    ---------------
 _____________________
/                     \
-----------------------
 \                   /
  -------------------

This is code-golf, so use any language, shortest code wins.

\$\endgroup\$
1
  • \$\begingroup\$ "Dad I'm hungry" "hi hungry I'm dad" "why did you name this way? Why why why?" \$\endgroup\$
    – lyxal
    Commented Dec 11, 2023 at 13:48

4 Answers 4

2
\$\begingroup\$

Perl 5 + -M5.10.0 -na, 169 bytes

say"I baked you a pie!
Oh boy, what flavour?
","PIE "x$_,"flavour.
",map{$i="  "x("@F"-$_)," __",_ x($#a=7+4*$_),"
$i/ @a \\
$i----",$j="-"x$#a,"
$i \\@a/
$i  $j
"}0..$_

Try it online!

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

JavaScript (ES6), 176 bytes

Builds the output recursively, from bottom to top.

f=(n,p,s=`I baked you a pie!
Oh boy, what flavour?
`)=>~n?f(n-1,-~p,s+=n?"PIE ":`flavour.
`)+`
 _2_
/ 0 \\
--1--
 \\0/
  1`.replace(/^|\d/gm,i=>" -_"[+i].repeat(i?7+n*4:p*2)):s

Try it online!

Commented

f = (                       // f is a recursive function taking:
  n,                        //   n = input
  p,                        //   p = left-padding counter
  s =                       //   s = header string
  `I baked you a pie!\n` +  //
  `Oh boy, what flavour?\n` //
) =>                        //
~n ?                        // if n is greater than -1:
  f(                        //   do a recursive call:
    n - 1,                  //     decrement n
    -~p,                    //     increment p
    s += n ? "PIE "         //     append "PIE " to s if n != 0
           : `flavour.\n`   //     or the final part otherwise
  ) + (                     //   end of recursive call
    `\n` +                  //  \   
    ` _2_\n` +              //   |  this is our pie template
    `/ 0 \\\n` +            //   |_ where digits 0, 1 and 2
    `--1--\n` +             //   |  are used as placeholders
    ` \\0/\n` +             //   |  for repeated characters
    `  1`                   //  /
  ).replace(                //   replace in the template:
    /^|\d/gm,               //   each beginning of line and
    i =>                    //   each digit with:
    " -_"[+i]               //     one of these characters
    .repeat(                //     repeated:
      i ?                   //       if this is a digit:
        7 + n * 4           //         7n + 4 times
      :                     //       else (left padding):
        p * 2               //         2p times
    )                       //     end of repeat()
  )                         //   end of replace()
:                           // else:
  s                         //   return the header string
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 126 bytesUTF-8 (87) bytes)

Ý·ε5+'_×1ú'/'-6y+×D„ \s¨¨2ú).B.º}˜.c…PIEIиðý.•FóG ñ•ÁDŠ“I baked€î€…Èš!
Ohíå,€Àÿ?
ÿÿ.

ÿ

Try it online.

†: Could be 86 bytes by using .•FóG ñ•Á instead of " flavour", but the longer one is cheaper in UTF-8 encoding.. 😒
Try it online.

Explanation:

Ý                # Push a list in the range [0, (implicit) input]
 ·               # Double each value in this list
  5+             # Then add 5 to each value
    ε            # Map over each 2v+5 value `y`:
     '_×        '#  Push a string of that many "_"
        1ú       #  Prepend a leading space
     '/         '#  Push "/"
     '-y>×      '#  Push a string with y+1 (2v+6) amount of "-"
     D           #  Duplicate it
     „ \         #  Push string " \"
     s           #  Swap so the duplicated "-"-string is at the top again
      ¨¨         #  Remove two "--" (2v+4 amount of "-")
        2ú       #  And pad two leading spaces instead
          )      #  Wrap all five strings into a list
           .B    #  Add trailing spaces to make all strings the same length
             .º  #  Mirror each line with overlap
  }˜             # After the map: flatten the list of lists of lines
    .c           # Add leading spaces to centralize all lines,
                 # and join all lines with newline delimiter
…PIE             # Push string "PIE"
    Iи           # Repeat it the input amount of times as list
      ðý         # Join it with space delimiter
.•FóG ñ•         # Push compressed string "flavour "
        Á        # Rotate it to " flavour"
         D       # Duplicate it
          Š      # Tripleswap the top three values on the stack
“I baked€î€…Èš!  # Push dictionary string "I baked you a pie!
Ohíå,€Àÿ?        # Oh boy, what pie?
ÿÿ.              # ÿÿ.
                 # 
ÿ                # ÿ",
                 # where the ÿ are one by one filled with the strings on the stack
                 # (after which it is output implicitly as result)

See this 05AB1E tip of mine (sections How to use the dictionary? and How to compress strings not part of the dictionary?) to understand why .•FóG ñ• is "flavour " and “I baked€î€…Èš!\nOhíå,€Àÿ?\nÿÿ.\n\nÿ is "I baked you a pie!\nOh boy, what pie?\nÿÿ.\n\nÿ".

\$\endgroup\$
1
\$\begingroup\$

Charcoal, 88 characters, 140 bytes

NθI baked you a pie!¶Oh boy, what flavour?¶×PIE θflavour.D⎚DF⁺⁵⊗…⁰⊕θ«←×_ι↓ /P⊕ι↘-\⊖ι↙»‖B

Attempt This Online! Explanation:

Nθ

Input the number of PIEs.

I baked you a pie!¶Oh boy, what flavour?¶×PIE θflavour.D⎚

Output the desired text.

Output an extra blank line.

F⁺⁵⊗…⁰⊕θ

Loop over the half pie widths.

«←×_ι↓ /P⊕ι↘-\⊖ι↙»

Draw the left half of a pie to the canvas.

‖B

Reflect to complete the pies.

Would be 83 SBCS bytes using string compression:

Nθ”(KRC¿~8◨±⦄⊕⁰↙]V⊕ACY>|⊙C↙∕›…<·DÞ↖pÞ”×PIE θflavour.D⎚DF⁺⁵⊗…⁰⊕θ«←×_ι↓ /P⊕ι↘-\⊖ι↙»‖B

Attempt This Online! Link is to verbose version of code.

\$\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.