10
\$\begingroup\$

Literally! April 6th is National Teflon Day, which is celebrated with Teflon-coated pans (what we will be making). So, given a positive integer n, create a Teflon pan. The "pan" section of the pan is an octagon with each of its sides consisting of n characters, which will vary depending on which side it is except for the sides using the character { or }. Those sides will have a character length of one always. If n is 1:

  _
 / \
{   }
 \_/

As you can see, each side consists of one character (either {, }, /, \, or _). If n is 2:

   __
  /  \
 /    \
{      }
 \    /
  \__/

The handle will be created with n+3 ='s and end with a zero (0).


If n is one:

  _
 / \
{   }====0
 \_/

n is 2:

   __
  /  \
 /    \
{      }=====0
 \    /
  \__/  

n is 3:

    ___
   /   \
  /     \
 /       \
{         }======0
 \       /
  \     /
   \___/  

If n is 4:

     ____
    /    \
   /      \
  /        \
 /          \
{            }=======0
 \          /
  \        /
   \      /
    \____/  

Rules and Criterion

  • No loopholes allowed

  • Handle comes out the right hand side (the side made of the } character)

  • Input is a positive integer

  • If the side does not consist of either { or } (not the left or right side), they will consist of n respective characters:

                _
               / \
    Left side {   } Right side
               \_/
    
  • Since this is , shortest code wins!
\$\endgroup\$
  • \$\begingroup\$ Could you please add more test cases? \$\endgroup\$ – xnor Apr 6 '17 at 22:37
  • \$\begingroup\$ @xnor Added two more \$\endgroup\$ – Anthony Pham Apr 6 '17 at 22:41
  • \$\begingroup\$ The test cases for n=3 and n=4 don't have the right number of characters on the top or bottom edges \$\endgroup\$ – fəˈnɛtɪk Apr 6 '17 at 23:04
  • \$\begingroup\$ @fəˈnɛtɪk Thanks! That has been fixed \$\endgroup\$ – Anthony Pham Apr 6 '17 at 23:25
  • \$\begingroup\$ Can I take O instead of 0 for the knob? \$\endgroup\$ – Titus Apr 7 '17 at 4:31

10 Answers 10

9
\$\begingroup\$

Charcoal,  41 38 36 30 28 bytes

Thanks to @Emigna for helping to save two bytes, thanks to @ASCII-only for saving six bytes, and thanks to @Neil for saving another two bytes!

Nη↙η↑←×_η↖η↗{↗η×_η↓↘η}×=⁺³η0

Try it online!

Explanation:

Nη                 // Take the size of the pan as input.
↙η                 // Draw a line of η '\'s going down to the left.
↑←×_η              // Move one step up and print η underscores to the left.
↖η↗{↗η             // Print a line of η '\'s going up to the left.
                   // Then move one step north-east and print '{'.
                   // Then print a line of η '/'s going up to the right.
×_η↓               // Print '_' η times and move one step down.
↘η}                // Draw a line of η '\'s going down to the right, then print '}'.
×=⁺³η              // Print '=' η+3 times.
0                  // Print '0'
\$\endgroup\$
  • 1
    \$\begingroup\$ You can move left of the starting point in Charcoal can't you? If so, starting at the tip of the handle should save a few bytes by not having to backtrack already printed space. \$\endgroup\$ – Emigna Apr 7 '17 at 6:15
  • \$\begingroup\$ @Emigna Thanks, I didn't know that. I had never used Charcoal before. \$\endgroup\$ – Steadybox Apr 7 '17 at 12:05
  • 1
    \$\begingroup\$ @Steadybox 30 bytes: Nη↖ηG←η_↙↙η{↓↘ηM↑×η_↗η}×⁺³η=P0 \$\endgroup\$ – ASCII-only Apr 9 '17 at 23:44
  • 1
    \$\begingroup\$ 28 bytes: Nη↙η↑←×_η↖η↗{↗η×_η↓↘η}×=⁺³η0 (1 byte saved by printing the bottom half of the pan first making the unnecessary and 1 byte saved by reversing the parameters to × making the unnecessary.) \$\endgroup\$ – Neil Dec 28 '17 at 15:39
7
\$\begingroup\$

JavaScript (ES6), 171 bytes

f=
n=>(r=s=>s[0][0].repeat(n-1)+s)`  `+r`_
`+r` `.replace(/ /g," $'/$' $`$`$`\\\n")+`{`+r` `+r` `+r` }`+r`====0`+r` `.replace(/ /g,"\n $`\\$` $'$'$'/").replace(/ +\/$/,r`_/`)
<input type=number min=1 oninput=o.textContent=f(this.value)><pre id=o>

The whole pizza pan is very repetitious so the r function (designed as a tagged template literal) repeats the first character of its input n times. This handles the top and middle and lines of the pan. The rest is repeated by replacing a string of blanks; the $` and $' subsitutions automatically correspond to increasing and decreasing numbers of blanks thus positioning the / and \ appropriately. Finally the _s are filled in on the last line as it's subtly different from the second line in that respect.

\$\endgroup\$
7
\$\begingroup\$

JavaScript + HTML, 575 bytes (451 bytes only JS) 376 bytes (482 bytes only JS)

y=document,y.y=y.getElementById,a=(b,c)=>{w="";for(z=0;z<b;z++)w+=c;return w},d=_=>{n=Number(y.y("n").value);s="";u=" ";j="<br>",m="\\",o="/";for(i=-2;i<=2*n;i++)-2==i?s+=a(n+1,u)+a(n,"_")+j:i<n-1?s+=a(n-i-1,u)+o+a(2*(i+1)+n,u)+m+j:i==n-1?s+="{"+a(3*n,u)+"}"+a(n+3,"=")+"0"+j:i+1==2*n?s+=a(n,u)+m+a(n,"_")+o:i+1<2*n&&(s+=a(i-n+1,u)+m+a(5*n-2*i-2,u)+o+j);y.y("p").innerHTML=s};
<input type="number" id='n'><button onclick='d()'>Do</button><p id='p' style='font-family:monospace;'></p>

Not a complicated approach: several string concatenations using conditions for the five different parts of the pan: the uppermost, lowermost and middle lines and the upper and lower halves.

I shortened as much as I could, but it was the limit with this method.

EDIT: it wasn't - additionally golfed by @programmer5000

\$\endgroup\$
  • \$\begingroup\$ Great first answer! Welcome to Programming Puzzles and Code Golf! \$\endgroup\$ – Anthony Pham Apr 7 '17 at 1:33
  • \$\begingroup\$ Was it great? I mean, it took much more time to make than it should have been and is not even really short - but thanks anyway! \$\endgroup\$ – Zoltán Schmidt Apr 7 '17 at 1:38
  • \$\begingroup\$ You should visit the question on golfing tips for Javascript \$\endgroup\$ – Anthony Pham Apr 7 '17 at 1:40
  • \$\begingroup\$ Didn't know there are tips too - thanks! \$\endgroup\$ – Zoltán Schmidt Apr 7 '17 at 1:47
  • 2
    \$\begingroup\$ Welcome to PPCG. For me any answer that shows some effort and a serious attempt to meet the challenge is a good answer and deserves an upvote. Good luck with the hints and tips. My first tip would be, stop thinking like the kind of programmer that you would want to work on a project with and start doing all of the things that you hate when you take over someone elses code (one letter variables, shortcut if statements, etc.) :) \$\endgroup\$ – ElPedro Apr 7 '17 at 19:13
4
\$\begingroup\$

PHP, 174 bytes

echo($p=str_pad)("",-$i=-1-$n=$argn),$p(_,$n,_);for(;$i++<$n;)echo$p("
",1+$a=abs($i)),$i?$p("\/"[$i<0],1+$n*3-$a*2,"_ "[$i<$n])."\/"[$i>0]:$p("{",$n*3).$p("} ",5+$n,"="). 0;

Takes input from STDIN; run with -nR or test it online.

breakdown

// first line
echo($p=str_pad)("",-$i=-1-$n=$argn),$p(_,$n,_);
// loop $i from -$n to $n
for(;$i++<$n;)echo
    $p("\n",1+$a=abs($i)),                  // 1. left padding
$i?                     // if not middle line:
    $p("\/"[$i<0],1+$n*3-$a*2,"_ "[$i<$n])  // 2. left edge and inner padding
    ."\/"[$i>0]                             // 3. right edge
:                       // else:
    $p("{",$n*3)                            // 2. left edge and inner padding
    .$p(" }",5+$n,"=")                      // 3. right edge
    . 0                                     // 4. knob
;
\$\endgroup\$
4
\$\begingroup\$

Python 3, 196 bytes

n=int(input())
p=print
s=' '
def m(i,f,b,c=s):p(s*(n-i)+f+c*(n+2*i)+b)
p(s*n+s+'_'*n)
for i in range(n):m(i,*'/\\')
p('{'+s*n*3+'}'+'='*(n+3)+'0')
for i in range(n-1,0,-1):m(i,*'\\/')
m(0,*'\\/_')

I used a few variables to shorten the code, but it's mostly straightforward. Here's a longer, more readable version:

n = int(input())

def middle_part(i, first_slash, second_slash, middle_char=' '):
    print(' ' * (n-i) + first_slash + middle_char * (n + 2*i) + second_slash)

print(' ' * (n+1) + '_' * n)

for i in range(n):
    middle_part(i, '/', '\\')

print('{' + ' ' * n*3 + '}' + '=' * (n+3) + '0')

for i in range(n-1, 0, -1):
    middle_part(i, '\\', '/')

middle_part(0, '\\', '/', middle_char='_')

Edit: changed to read n from stdin, 181 → 196 bytes

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

Python 2, 180 178 bytes

s,i=' ',input();R=range(i)
print'\n'.join([s+s*i+'_'*i]+[s*(i-a)+'/'+s*(i+a*2)+'\\'for a in R]+['{'+s*i*3+'}'+'='*(i+3)+'0']+[s*(i-c)+'\\'+'_ '[c>0]*(i+c*2)+'/'for c in R[::-1]])

Try it online!

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

Python 2.7, 194 195 191 187 185 bytes

n=input();s=' ';a='\\';z='/'
def m(f,b,i,c=s):print(n-i)*s+f+c*(n+2*i)+b
m(s,s,0,'_')
for i in range(n):m(z,a,i)
print'{'+s*n*3+'}'+'='*(n+3)+'0';exec"m(a,z,i);i-=1;"*(n-1);m(a,z,0,'_')

Try it online!

Open to edit suggestions to make it smaller. :)

Edit 1: +1 byte - Credits to ElPedro for pointing out an error in the code, which made it 1 byte longer.

Edit 2: -4 bytes - Credits to piyush-ravi for removing unneccesary arguments.

Edit 3: -4 bytes - How did I not see that? :P

Edit 4: -2 bytes - Replacing '\n' with ';'

\$\endgroup\$
  • \$\begingroup\$ It looks looks the first line below the middle line should not be there when I try it locally. tried it for input 4 and 3 and it looks wrong. Won't retract the upvote until you have had time to review and explain or fix though. My fault for not looking hard enough :) \$\endgroup\$ – ElPedro Apr 7 '17 at 19:06
  • \$\begingroup\$ Thanks for pointing it out ElPedro. Fixed it :) \$\endgroup\$ – Koishore Roy Apr 9 '17 at 6:21
2
\$\begingroup\$

PowerShell, 165 bytes

param($n)($a=' '*$n)+" "+($b='_'*$n);$n..1|%{' '*$_+"/"+' '*($n+2*$i++)+"\"};"{$($a*3)}$('='*($n+3))0";if($n-1){1..($n-1)|%{' '*$_+"\"+' '*($n+2*--$i)+"/"}};"$a\$b/"

Try it online!

Takes input $n, sets $a to a bunch of spaces, $b to a bunch of underscores, and string concatenates that with a space. That's left on the pipeline.

Loops from $n down to 1. If $n=1, this will only execute once. Each iteration we do a string concatenation of spaces, a /, more spaces with counter $i, and a \. Those are all left on the pipeline.

Then comes the middle part with the handle, which coincidentally has $a*3 spaces in the middle, and $n+3 = signs, then a 0. That's left on the pipeline.

If $n is bigger than 1, then $n-1 is truthy so we enter the conditional, where we loop the other direction to form the bottom of the pan. If $n=1, then we don't need this portion due to how the lines work. Those are all left on the pipeline. We finish off with the spaces and underlines with the $a\$b/ bottom of the pan.

All those strings from the pipeline are sent via implicit Write-Output that prints them with newlines in between elements.

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

JavaScript + HTML - 346 bytes

JavaScript - 314 bytes, HTML - 32 bytes

function o(a){a=parseInt(a),String.prototype.r=String.prototype.repeat;c=console.log,d=" ".r(a),e="_".r(a);c(" "+d+e);for(f=a-1,g=a;f>=0;f--,g+=2)c(" ".r(f+1)+"/"+" ".r(g)+"\\");c("{ }=0".replace(" "," ".r(3*a)).replace("=","=".r(a)));for(f=0,g=3*a;f<a-1;f++,g-=2)c(" ".r(f+1)+"\\"+" ".r(g-2)+"/");c(d+"\\"+e+"/")}
<input id=n onkeyup=o(n.value)>

Un-golfed

function o(sides) {

  String.prototype.r = String.prototype.repeat;
  var middle = '{ }=0',
  log = console.log,
  ss = ' '.r(sides),
  u = '_'.r(sides),
  sides = parseInt(sides);

  // top
  log(' ' + ss + u);

  // top mid
  for (var i = sides - 1, j = sides; i >= 0; i--, j += 2) {
    log(' '.r(i + 1) + '/' + ' '.r(j) + '\\');
  }

  // mid
  log('{ }=0'.replace(' ', ' '.r(sides * 3)).replace('=', '='.r(sides)));

  // bottom mid
  for (var i = 0, j = sides * 3; i < sides - 1; i++, j -= 2) {
    log(' '.r(i + 1) + '\\' + ' '.r(j - 2) + '/');
  }

  // bottom
  log(ss + '\\' + u + '/');

}
<input id="n" onkeyup="o(n.value)">

\$\endgroup\$
0
\$\begingroup\$

C, 249 bytes

o(c,a){for(;a--;)putchar(c);}s;p(n){o(32,n+1);o(95,n);o(10,1);for(s=0;s<n;s++)o(32,n-s),o(47,1),o(32,n+s*2),o(92,1),o(10,1);o(123,1);o(32,n*3);o(125,1);o(61,3+n);o(48,1);o(10,1);for(s=n-1;s>-1;s--)o(32,n-s),o(92,1),o(s?32:95,n+s*2),o(47,1),o(10,1);}

Try it online

\$\endgroup\$

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.