7
\$\begingroup\$

Backstory

Not really real, sshh!

It all started one day when a coworker brought in a homemade loaf of bread for my boss's birthday.

My boss really liked this loaf of bread, and he wanted another. Unfortunately, my coworker has quit, so my boss needs me to give him another loaf.

The problem is, I have no idea how to make bread. So I told my boss that i'm not a chef and to look harder for someone who is.

He said, "Sure...but you lose your job if you can't make me a loaf."

Then I had an idea.

I would make him an loaf with my coding skilz! He said yes, under 1 condition: "You must make it in under 351 bytes." Unfortunately for me, my best code golfing got me to 375 bytes. Uh oh.

Then my boss added 2 things: "You must give me that loaf in a week (4/13), and if you do so you get an increased salary. The lower the amount of bytes you use, the better salary. But remember, if you go over 349 you lose your job."

So I need your help in your language of choice to help me keep my job!

Rules

I was about to do a curl ... | sh on a TinyURL, but my boss told me that I can't use a list of loopholes. I probably could skirt the rules, but my job is at stake, so it's not a good idea.

What counts as a loaf

Your program or function must take 3 positive integers as input. If your language has a list or array, you can take a list or array of those numbers. You can also take them as arguments to a function or program, or a space-separated string of numbers to STDIN, a command-line or function argument, etc.

The first number is the width of your loaf

The second number is the height of your loaf.

The third number is the depth of your loaf.

Here's a loaf with a width of 3, a height of 2, and a depth of 1:

 /---\
/---\|
|   ||
|___|/

Looks wierd? Here's a 3x2x2:

  /---\
 /    |
/---\ |
|   | /
|___|/

How about a 3x3x3:

   /---\
  /    |
 /     |
/---\  |
|   |  /
|   | /
|___|/

A 4x1x2:

  /----\
 /     |
/----\ /
|____|/

I hope you understand! See my JS (ES6) answer below for an example.

Also see complete test cases

Notes:

  • Don't worry about valid input. All sizes will be positive integers.
  • You must accept any positive integers that your language can support.
  • If the numbers are so high your languages crashes from StackOverflow, maximum string length overflow, etc. that's OK.

Shortest answer in bytes wins!

\$\endgroup\$
3
  • 2
    \$\begingroup\$ I guess if you had used Charcoal you could have asked for a 10% raise... :) \$\endgroup\$
    – ElPedro
    Apr 6, 2017 at 19:44
  • \$\begingroup\$ What about 350 bytes? \$\endgroup\$
    – boboquack
    Apr 7, 2017 at 3:27
  • 1
    \$\begingroup\$ "You must make it in under 351 bytes". "Remember, if you go over 349 bytes, you lose your job". What do you actually mean? Please be consistent with yourself. \$\endgroup\$
    – hyper-neutrino
    Apr 9, 2017 at 0:59

6 Answers 6

7
\$\begingroup\$

Charcoal, 35 33 30 bytes

Saved 2 bytes thanks to @ASCII-only

Saved 3 bytes thanks to @Neil by rearranging the order in which the lines where drawn

NωNηNδ↓η↗→×_ω↑η←\←ω↗δ→/ω↓\↓η↙δ

Try it online!

This is my first try at Charcoal. I heard it was good at , so I tried it out.

Explanation (outdated)

NωNηNδ                  # Take the width, height and depth as input
↗¹                        # Write 1 /
↗δ                        # Write depth times /
¶ω                        # Move the cursor down and write - width times
\                         # Write \
↙↓η                       # Move the cursor one down and one left, and then write | height times
↙δ                        # Write / depth times

Now the back part of the loaf is complete. Now comes the front face.

↑↑η                       # Go up and write | height times
←\                        # Write a \ and move 1 to the left
←ω                        # Write - width times
↓↓η                       # Go down and write | height times
↗P×_ω                    # Go northeast and write _ width times
\$\endgroup\$
7
  • 1
    \$\begingroup\$ That's just plain cool! \$\endgroup\$
    – ElPedro
    Apr 6, 2017 at 18:14
  • \$\begingroup\$ hahaha I knew it soon as I saw the ascii loaf...! \$\endgroup\$
    – Nelson
    Apr 6, 2017 at 19:39
  • \$\begingroup\$ You can replace ↓→ with (newline), and \←←←ω with ←\←ω \$\endgroup\$
    – ASCII-only
    Apr 10, 2017 at 0:11
  • \$\begingroup\$ @ASCII-only Thanks for the tips :) \$\endgroup\$
    – user41805
    Apr 10, 2017 at 9:54
  • \$\begingroup\$ Your explanation has ←\← but the second belongs before the ω on the next line. ↗δ→/ is a byte shorter than ↗¹↗δ¶, but I also saved a couple more bytes by rearranging the order in which the lines were drawn: Try it online! \$\endgroup\$
    – Neil
    May 25, 2017 at 21:31
3
\$\begingroup\$

JS (ES6), 375 bytes

s=(s,t)=>s.repeat(t);(d,c,e)=>{z=" ",y=`
`,x="\\",w="/",v="|",u="-";a=s(z,e--);a=a+w+s(u,d);a+=x+y;for(b=0;b<e;b++)a+=s(z,e-b),b<c?(a+=w,a+=s(z,d+b+1),a+=v):(a+=w,a+=s(z,d+c+1),a+=w),a+=y;a=a+w+s(u,d);a+=x;f=0;b<c?(a+=s(z,e),a+=v):(a+=s(z,c-f),a+=w);b++;f++;a+=y;for(g=0;g<c;g++)a+=v,a+=s((g==c-1?"_":z),d),a+=v,b<c?(a+=s(z,e),a+=v):(a+=s(z,c-f),a+=w),b++,f++,a+=y;return a}

Ungolfed:

var proc = function(width, height, depth){
    var str = "";

    //Back of loaf (depth)
    str += " ".repeat(depth);//initial padding before start of back of loaf
    str += "/";//top left corner of back of loaf
    str += "-".repeat(width);//top edge of back of loaf
    str += "\\";//top left corner of back of loaf
    str += "\n";//end line

    //Depth lines
    for(var i = 0; i < depth - 1; i++){
        console.log(i)
        str += " ".repeat(depth - i - 1);//space padding before start of left middle edge
        if(i < height){
            //str += " ".repeat(depth - i - 2);
            str += "/";//left middle edge
            str += " ".repeat(width + i + 1);//middle of loaf
            str += "|";//end that edge
            str += "\n";//end line
        }else{
            str += "/";//left middle edge
            str += " ".repeat(width + height + 1);//between two /s
            str += "/";//right middle edge
            str += "\n";//end line
        }
    }

    //front top edge of loaf
    str += "/";//top left corner
    str += "-".repeat(width);//top edge
    str += "\\";//top right corner

    var i3 = 0;

    if(i < height){
        str += " ".repeat(depth - 1);//space for the incoming far right edge
        str += "|";//far right edge
        i++;
        i3++;
    }else{
        str += " ".repeat(height - i3);//space for the incoming far right edge
        str += "/";//far right edge
        i++;
        i3++;
    }

    str += "\n";//newline


    for(var i2 = 0; i2 < height; i2++){
        str += "|";//left edge
        str += (i2 === height - 1 ? "_" : " ").repeat(width);//if we are at the bottom, use underscores to mark that, otherwise spaces.
        str += "|";
        if(i < height){
            str += " ".repeat(depth - 1);//space for the incoming far right edge
            str += "|";//far right edge
            i++;
            i3++;
        }else{
            str += " ".repeat(height - i3);//space for the incoming far right edge
            str += "/";//far right edge
            i++;
            i3++;
        }
        str += "\n";//newline
    }

    return str;
};

s=(s,t)=>s.repeat(t);
var bakeBread = (d,c,e)=>{z=" ",y=`
`,x="\\",w="/",v="|",u="-";a=s(z,e--);a=a+w+s(u,d);a+=x+y;for(b=0;b<e;b++)a+=s(z,e-b),b<c?(a+=w,a+=s(z,d+b+1),a+=v):(a+=w,a+=s(z,d+c+1),a+=w),a+=y;a=a+w+s(u,d);a+=x;f=0;b<c?(a+=s(z,e),a+=v):(a+=s(z,c-f),a+=w);b++;f++;a+=y;for(g=0;g<c;g++)a+=v,a+=s((g==c-1?"_":z),d),a+=v,b<c?(a+=s(z,e),a+=v):(a+=s(z,c-f),a+=w),b++,f++,a+=y;return a}
<input type = "number" id = "a1">
<br/>
<input type = "number" id = "a2">
<br/>
<input type = "number" id = "a3">
<br/>
<button onclick = "document.getElementById('textarea').innerText = bakeBread(+(document.getElementById('a1').value), +(document.getElementById('a2').value), +(document.getElementById('a3').value))">Bake Bread!</button>
<br/>
<textarea id = "textarea"></textarea>

\$\endgroup\$
2
  • 1
    \$\begingroup\$ "in under 351 bytes" Someone just got fired :( \$\endgroup\$
    – Shadow
    Apr 7, 2017 at 1:37
  • \$\begingroup\$ @shadow, actually, I need a < 351 bytes program to send to my boss. Any of the answers below will work! \$\endgroup\$
    – user58826
    Apr 7, 2017 at 11:39
3
\$\begingroup\$

C, 270 290 320 328 bytes

#define P printf(
p(n,s)char*s;{P s,--n&&p(n,s));}i,j,k;f(w,h,d){P "%*c",d+1,47);p(w,"-");P "\\\n");for(i=d,j=h,k=0;--i;)P "%*c%*c\n",i+1,47,w+d+1-i-k+!!k,j-->0?124:(++k>0)*47);P "/");p(w,"-");P "\\%*c\n",d-k,j-->0?124:47);for(k&&k++;++i<h;)P "|%*c%*c\n",w+1,124,d-k>!k?d+1-k-!k:0,j-->0?124:(++k>0)*47);P "|");p(w,"_");P "|/");}

Finally (after two three incorrect versions) it works correctly with large sizes also.

Try it online!

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

Python 2, 234 216 210 bytes

w,h,d=input()
f,g='|','/';z,s=g+'-'*w+'\\',' '
print'\n'.join([s*d+z]+[s*(d-c)+g+s*(w+c)+(f,g)[c>h]for c in range(1,d)]+[z+s*(d-1)+(f,g)[d>h]]+[f+s*w+f+s*(h-e-1)+(f,s+g)[d>=h]for e in range(1,h)]+[f+'_'*w+f+g])

Try it online!

Sure it can be golfed a lot more but it's a start. 210 will do for me for now.

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

JavaScript (ES6), 204 bytes

(w,h,d)=>[...Array(h-~d)].map((_,y)=>[...Array(w-~d)].map((_,x)=>x+y==d|x+y==h+w-~d?`/`:x==w+d&y<=h&&y||!x|x==w&&y>d?`|`:y==h+d&x<w?`_`:!y|y==d?x+y==w+d?`\\`:x+y>d&x+y<w+d?`-`:` `:` `).join``,++w).join`\n`

Where \n represents the literal newline character.

Rather than fiddle around with repeating characters, this just creates a suitably sized array and computes which character appears in each cell.

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

PHP, 420 bytes

<?php $a=$_GET["a"];$b=$_GET["b"];$c=$_GET["c"];$w="<br>";$s="&nbsp;";$u="&#95";$p="|";$k="/";$t=str_repeat;$l='';$r=$t($s,$c).$k.$t("-",$a)."\\".$w;for($i=0;$i<$c+$b-1;$i++){$i<=$b-1?($i<$c-1?$l=$t($s,$a+$i+1).$p:$l=$t($s,$c-1).$p):($i<$c-1?$l=$t($s,$a+$b+1).$k:$l=$t($s,$c+$b-$i-1).$k);$i<$c-1?$r.=$t($s,$c-$i-1).$k.$l.$w:($i==$c-1?$r.=$k.$t("-",$a)."\\".$l.$w:$r.=$p.$t($s,$a).$p.$l.$w);};echo$r.=$p.$t($u,$a).$p.$k?>

Sounds like someone's fired - maybe try convincing your boss that it's much cooler on backend.

Input is attached to the URL string: ?a=[width]&b=[height]&c=[depth].

Ungolfed for transparency:

<?php 
$a=$_GET["a"];$b=$_GET["b"];$c=$_GET["c"];
$w="<br>";$s="&nbsp;";$u="&#95"; $p="|";$k="/";$t=str_repeat;$f=$v=$m=$l='';
//first line
$r=$t($s,$c).$k.$t("-",$a)."\\".$w;


for($i=0;$i<$c+$b-1;$i++){

    //right side of the loaf
    $i <= $b-1 
    ? ($i < $c-1 ? $l=$t($s,$a+$i+1).$p : $l=$t($s,$c-1).$p)  
    : ($i < $c-1 ? $l=$t($s,$a+$b+1).$k : $l=$t($s,$c+$b-$i-1).$k) ;

    //left side, with the right side attached
    $i<$c-1 
        ? $r.=$t($s,$c-$i-1).$k.$f.$l.$w
        : ($i==$c-1 
            ? $r.=$k.$t("-",$a)."\\".$f.$l.$w
            : $r.=$p.$t($s,$a).$p.$f.$l.$w);

};
    //final line
    echo $r.=$p.$t($u,$a).$p.$k;

?>
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.