40
\$\begingroup\$

Today is Bacon Day which is probably why the name of the hat for participating today is "Mmmm Bacon". What better way to celebrate bacon day with fun filled 2d matrices made out of bacon! A 1 by 1 bacon strip is represented by this:

----- 
)===)
(===(
)===)
-----

You goal here is given two coordinates in a tuple, (x, y), where x and y are nonzero positive integers, you are to create the bacon and return in some format (list, array, string).

Input and Output:

Input: (2, 1)

Output:
----------  
)===))===)
(===((===(
)===))===)
----------

Input: (1, 2)

Output:

----- 
)===)
(===(
)===)
----- 
)===)
(===(
)===)
-----

Input: (2, 2)

---------- 
)===))===)
(===((===(
)===))===)
---------- 
)===))===)
(===((===(
)===))===)
----------

Rules:

  • As you can see with the second test case, if multiple pieces of bacon are stacked together, only one ----- separates with each piece of bacon above and/or below it. That means stacking bacon like this is invalid:

    ----- 
    )===)
    (===(
    )===)
    -----
    ----- 
    )===)
    (===(
    )===)
    -----   
    
  • Standard loopholes are forbidden

  • The code must work for the above test cases and the following: (4, 4), (1, 6), (5, 1), (2, 3), (3, 2)

  • Provide an interpreter where the above test cases can be tested

Winning Criteria:

Shortest code wins! Happy Bacon Day to everyone!

\$\endgroup\$
  • \$\begingroup\$ This conversation has been moved to chat. \$\endgroup\$ – Dennis Dec 31 '16 at 22:46

21 Answers 21

11
\$\begingroup\$

V, 28, 26, 24 bytes

Ài)³=)Y4PÒ-G.MÓ)/(
kÀäG

Try it online!

Explanation:

Ài                      " Arg 1 times insert:
  )³=)                  " ')===)'
      <esc>             " Escape back to normal mode
           Y            " Yank this line
            4P          " Paste four times
              Ò-        " Replace this line with '-'
                G.      " Repeat on the last line
                  M     " Move to the middle line
                   Ó)/( " Replace ')' with '('
k                       " Move up (to the second line)
 À                      " Arg 2 times
  äG                    " Duplicate everything up to the last line
\$\endgroup\$
  • 3
    \$\begingroup\$ I love how this answer is only 3 bytes longer than a single bacon :D \$\endgroup\$ – FlipTack Dec 30 '16 at 18:28
  • 3
    \$\begingroup\$ @FlipTack There are Newlines. It's actually 2 shorter. :P \$\endgroup\$ – DJMcMayhem Dec 30 '16 at 18:29
  • 2
    \$\begingroup\$ Forgot about that! Wow, an answer that's shorter than the building blocks of the output. This is some dennis-style stuff going on. \$\endgroup\$ – FlipTack Dec 30 '16 at 19:05
8
\$\begingroup\$

TI-Basic, 80 bytes

This one was actually quite genius :)

":→Str0:Input :For(M,0,4Y:For(N,1,X:")===)
If not(fPart(M/4:"-----
If .5=fPart(M/4:"(===(
Str0+Ans→Str0:End:Ans+":→Str0:End
\$\endgroup\$
  • \$\begingroup\$ Also, for anyone wondering, in TI-Basic the colon and newline are interchangeable, and using Input with no arguments gets input by default into X and Y. \$\endgroup\$ – Timtech Dec 30 '16 at 21:45
7
\$\begingroup\$

Python 2.7, 74 bytes

I'm sure this could be golfed some more, but this is what I came up with (Python's string multiplication feature sure comes in handy):

a,b=input();f="-"*5*a;d=")===)"*a;print'\n'.join([f,d,"(===("*a,d,''])*b+f

Try it here!

Ungolfed with explanation:

a,b = input()                                       # Take input from the user as a tuple
f = "-"*5 * a                                       # f is the delimiter between bacons
d = ")===)" * a                                     # 2nd and 4th lines of bacon
print '\n'.join([f, d, "(===("*a, d, ''])*b + f     # Join everything together!
\$\endgroup\$
5
\$\begingroup\$

Mathematica, 74 bytes

Array[b["-----",b=")===)","(===("][[#~Mod~4]]&,{4#2+1,#}]~Riffle~"\n"<>""&

Unnamed function taking two positive integer arguments and returning a string-with-newlines. A standard Mathematica approach: build a 2d array of strings using a (mod 4) chooser to cycle the strings in the vertical direction, then collapse them to a single string.

\$\endgroup\$
4
\$\begingroup\$

Batch, 168 bytes

@set s=
@for /l %%i in (1,1,%1)do @call set s=%%s%%-___-
@set t=%s:_==%
@echo %s:_=-%
@for /l %%i in (1,1,%2)do @echo %t:-=)%&echo %t:-=(%&echo %t:-=)%&echo %s:_=-%

Rather unfortunately I can't write @echo %s:==-% otherwise that would eliminate the necessity for the second variable.

\$\endgroup\$
  • \$\begingroup\$ Save 2 bytes by concatenating lines 1,2 and 3,4 with &... \$\endgroup\$ – Magoo Dec 31 '16 at 7:23
4
\$\begingroup\$

C, 91 89 bytes

i;f(w,h){w=w*5+1;for(i=0;i<w*4*h+w;++i)putchar(i%w<w-1?i/w%4?i%w%5%4?61:40+i/w%2:45:10);}
\$\endgroup\$
4
\$\begingroup\$

05AB1E, 25 bytes

Code:

…)==û×Ь'(:s)¬g'-×=¸«»²F=

Explanation:

…)==û                         # Push the string ")===)"
     ×                        # String multiply by the first input
      Ð                       # Triplicate the string
       ¬                      # Take the first character, which is a ')' and push
        '(:                   # Replace by '('
           s                  # Swap the top two elements
            )                 # Wrap everything into an array
             ¬g               # Get the length of the first element in the array
               '-×            # And repeat the character '-' that many times
                  =           # Print it without popping
                   ¸«         # Append the string of dashes to the array
                     »        # Join by newlines
                      ²F      # Second input times do...
                        =     #   Print the top of the stack without popping

Uses the CP-1252 encoding. Try it online!

\$\endgroup\$
4
\$\begingroup\$

05AB1E, 32 30 bytes

Saved 2 bytes thanks to Adnan.

'-5×…)==ûÐ')'(:s)vy¹×})I.D¬)˜»

Try it online!

Explanation

'-5×                            # push "-----" 
    …)==ûÐ                      # push 3 copies of ")===)"
          ')'(:s                # replace ")" with "(" in the 2nd copy
                )               # wrap in list
                 vy¹×})         # repeat each list entry input-1 times
                       I.D      # repeat list input-2 times
                          ¬     # push the first element of the list ("-----")
                           )˜   # wrap in list and flatten
                             »  # join by newline
\$\endgroup\$
  • \$\begingroup\$ You can replace ")===)" by …)==û :) \$\endgroup\$ – Adnan Dec 31 '16 at 0:54
  • \$\begingroup\$ @Adnan: Ah of course! Thanks! \$\endgroup\$ – Emigna Dec 31 '16 at 10:19
3
\$\begingroup\$

Python 2, 70 bytes

def f(w,h):n=4*h+1;exec"n-=1;print'-)()-===-===-===-)()'[n%4::4]*w;"*n

Thanks to @xnor for saving 4 bytes!

Try it online!

\$\endgroup\$
  • \$\begingroup\$ It looks like the lines don't alternate directions in your test case. \$\endgroup\$ – xnor Dec 31 '16 at 1:02
  • \$\begingroup\$ It looks like a [_::3] would be shorter. \$\endgroup\$ – xnor Dec 31 '16 at 1:17
  • \$\begingroup\$ Oh shoot, something went wrong there. Deleting until I can fix it. \$\endgroup\$ – Dennis Dec 31 '16 at 1:19
  • \$\begingroup\$ That fixed my code without adding any bytes. Thanks! Let's see if I manage to deduplicate those lines again. \$\endgroup\$ – Dennis Dec 31 '16 at 1:34
  • \$\begingroup\$ There's 2**n%5%3 which cycles [1, 2, 1, 0, 1, 2, 1, 0, ...]. Might that be useful? \$\endgroup\$ – xnor Dec 31 '16 at 3:06
3
\$\begingroup\$

Python 2, 59 bytes

w,h=input()
for a in'-()('*h+'-':print(a+3*'=-'[a>')']+a)*w

Generates each line as a+b*3+a from the initial character a and the center character b (which is calculated from a). The a's cycle through '-()(', whereas b is '-' when a is '-', and '=' otherwise.


67 bytes:

w,h=input()
for a,b in['--']+zip(')()-','===-')*h:print(a+b*3+a)*w

Generates each line from its outer character a and center character b as a+b*3+a, then prints w copies of this. These cycle via a zip.

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

JavaScript, 132 129 121 bytes

-8 bytes thanks to @user2428118

(x,y)=>{a=b=["-----",")===)","(===(",")===)","-----"];for(i=0;++i<y;){b=[...b,...a.slice(1)]}return b.map(v=>v.repeat(x)).join(`
`)}

(x,y)=>eval('a=b=["-----",")===)","(===(",")===)","-----"];for(i=0;++i<y;)b=[...b,...a.slice(1)];b.map(v=>v.repeat(x)).join`\n`')

(x,y)=>eval('a=b=[c="-----",d=")===)","(===(",d,c];for(i=0;++i<y;)b=[...b,...a.slice(1)];b.map(v=>v.repeat(x)).join`\n`')

This can quite probably be golfed more. If you have a suggestion, please leave it in the comments.

\$\endgroup\$
  • \$\begingroup\$ beat me by 1 byte.. :( \$\endgroup\$ – devRicher Dec 30 '16 at 18:23
  • \$\begingroup\$ @devRicher But I haven't exactly golfed mine yet. :) \$\endgroup\$ – ericw31415 Dec 30 '16 at 18:39
  • \$\begingroup\$ @devRicher Actually I accidentally miscounted the newline. Whoops. Edit: I've beat you now. \$\endgroup\$ – ericw31415 Dec 30 '16 at 18:44
  • 1
    \$\begingroup\$ @ericw31415 (x,y)=>eval('a=b=[d="-----",c=")===)","(===(",c,d];for(i=0;++i<y;)b=[...b,...a.slice(1)].map(v=>v.repeat(x)).join_BACKTICK NEWLINE BACKTICK_;') \$\endgroup\$ – user2428118 Dec 30 '16 at 20:55
  • \$\begingroup\$ @user2428118 This doesn't work? I can use your array simplification though. :) \$\endgroup\$ – ericw31415 Dec 31 '16 at 22:41
2
\$\begingroup\$

Lua, 132 bytes

a="-----"b=")===)"c="(===("w,z=io.read(),io.read()function g(f)return f:rep(w).."\n"end print((g(a)..g(b)..g(c)..g(b)):rep(z)..g(a))

Long, literal string attempt. Try it here.

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

JavaScript (ES6), 78

(x,y,r=s=>`${s}`.repeat(x)+`
`,a=r`)===)`,c=r`-----`)=>c+r(a+r`(===(`+a+c,x=y)

Test

F=
(x,y,r=s=>`${s}`.repeat(x)+`
`,a=r`)===)`,c=r`-----`)=>c+r(a+r`(===(`+a+c,x=y)

function update() {
  var x=+X.value,y=+Y.value
  O.textContent=F(x,y)
}

update()
X<input type=number id=X value=1 min=1 oninput='update()'>
Y<input type=number id=Y value=1 min=1 oninput='update()'>
<pre id=O></pre>

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

GameMaker Language, 160 139 148 bytes 133 bytes

x=argument0 y=argument1*4for(m=0;m<=y;m++){for(n=0;n<x;n++){a=")===)"if !m mod 4a="-----"else if n mod 2a="(===("r+=a}r+="#"}return r
\$\endgroup\$
  • \$\begingroup\$ Also, before you suggest it, GML requires each part of the for loop to have a statement inside :( \$\endgroup\$ – Timtech Dec 30 '16 at 19:44
1
\$\begingroup\$

Jelly, 26 bytes

4“\ḊƭVṠ’bị“-=()”s5ẋ€ḷẋµ1ịṭ

This is a dyadic link (function) that returns a 2D array.

Try it online!

How it works

4“\ḊƭVṠ’bị“-=()”s5ẋ€ḷẋµ1ịṭ  Main link. Left argument: w. Right argument: h

4                           Set the return value to 4.
 “\ḊƭVṠ’b                   Yield 366323084456 and convert it to base 4.
                            This yields [1,1,1,1,1,0,2,2,2,0,3,2,2,2,3,0,2,2,2,0].
         ị“-=()”            Index into that string, using modular 1-based indexing.
                s5          Split the result into chunks of length 5.
                  ẋ€ḷ       Repeat the characters of each chunk w times.
                     ẋ      Repeat the array of chunks h times.
                      µ     Begin a new, monadic chain. Argument: M (bacon matrix)
                       1ị   Retrieve the first line.
                         ṭ  Tack; append it to M.
\$\endgroup\$
0
\$\begingroup\$

C, 159 158 153 bytes

p(s,n){printf(s,--n?p(s,n):0);}i,j;b(n,m){p("-----",n);for(j=3;j--;){p("\n",1);for(i=n;i--;)p(j%2?"(===(":")===)",1);}p("\n",1);--m?b(n,m):p("-----",n);}

Call with:

int main()
{
    b(2,3);
}
\$\endgroup\$
  • \$\begingroup\$ Nice to see another answer in C, but it can be done quite a bit shorter, see my answer :) \$\endgroup\$ – orlp Dec 30 '16 at 20:53
0
\$\begingroup\$

C#, 160 bytes

x=>y=>{int i=0,h=4*y+1,j;var s=new string[h];for(;i<h;++i)if(i%4<1)s[i]=new string('-',x*5);else{var c=i%2>0?')':'(';for(j=0;j++<x;)s[i]+=c+"==="+c;}return s;};

Formatted version:

x => y =>
{
    int i = 0, h = 4 * y + 1, j;

    var s = new string[h];

    for (; i < h; ++i)
        if (i % 4 < 1)
            s[i] = new string('-', x * 5);
        else
        {
            var c = i % 2 > 0 ? ')' : '(';

            for (j = 0; j++ < x; )
                s[i] += c + "===" + c;
        }

    return s;
};

Try it online! (for some reason this link gives an error but works anyway)

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

Dart, 125 117 bytes

(x,y){var t='-'*5*x,i=0;return()sync*{yield t;for(;i<y*4;i++)yield i%4>2?t:i%2>0?'(===('*x:')===)'*x;}().join('\n');}

Try it here!

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

Dyalog APL, 55 bytes

This is my first time using Dyalog APL, so I'm sure this isn't the best approach.

 {(⊂'-----'),[1]⍉⍺(4×⍵)⍴')===)' '(===(' ')===)' '-----'}

Explanation: This is a quite simple approach, for a bacon grid of N×M, I make an N×(4M) matrix of the following four strings, repeating:

')===)'
'(===('
')===)'
'-----'

Then I concatenate the string ----- to the beginning.

Here's a quick explanation of the code:

')===)' '(===(' ')===)' '-----'  ⍝ An array of the four strings        

⍺ (4×⍵) ⍴                        ⍝ reshape (⍴) the array to a matrix with the dimensions
                                 ⍝ ⍺ by (4×⍵) (⍺ is the 1st argument and ⍵ is the second) 

⍉                               ⍝ transpose the matrix 

,[1]                             ⍝ concatenate to beginning of the matrix...

(⊂'-----')                       ⍝ ...the string '-----' embedded in its own matrix (⊂)
\$\endgroup\$
0
\$\begingroup\$

Tcl, 91 bytes

time {time {append h -----
append l )===)
append p (===(} $m
puts "$h
$l
$p
$l"} $n
puts $h

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Do I need the put the input part? To account for the byte count? \$\endgroup\$ – sergiol Jan 4 '17 at 3:00
0
\$\begingroup\$

PowerShell, 64 bytes

param($x,$y)-split'----- )===) (===( )===) -----'*$y|gu|%{$_*$x}

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.