Happy Bacon Day!

40

3

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!

Anthony Pham

Posted 2016-12-30T17:30:07.313

Reputation: 1 911

This conversation has been moved to chat.

– Dennis – 2016-12-31T22:46:55.050

Answers

11

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

James

Posted 2016-12-30T17:30:07.313

Reputation: 54 537

3I love how this answer is only 3 bytes longer than a single bacon :D – FlipTack – 2016-12-30T18:28:17.300

3@FlipTack There are Newlines. It's actually 2 shorter. :P – James – 2016-12-30T18:29:51.283

2Forgot about that! Wow, an answer that's shorter than the building blocks of the output. This is some dennis-style stuff going on. – FlipTack – 2016-12-30T19:05:31.430

8

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

Timtech

Posted 2016-12-30T17:30:07.313

Reputation: 12 038

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. – Timtech – 2016-12-30T21:45:21.460

7

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!

Calconym

Posted 2016-12-30T17:30:07.313

Reputation: 459

5

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.

Greg Martin

Posted 2016-12-30T17:30:07.313

Reputation: 13 940

4

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.

Neil

Posted 2016-12-30T17:30:07.313

Reputation: 95 035

Save 2 bytes by concatenating lines 1,2 and 3,4 with &... – Magoo – 2016-12-31T07:23:25.637

4

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

Emigna

Posted 2016-12-30T17:30:07.313

Reputation: 50 798

You can replace ")===)" by …)==û :) – Adnan – 2016-12-31T00:54:35.320

@Adnan: Ah of course! Thanks! – Emigna – 2016-12-31T10:19:30.800

4

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);}

orlp

Posted 2016-12-30T17:30:07.313

Reputation: 37 067

4

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!

Adnan

Posted 2016-12-30T17:30:07.313

Reputation: 41 965

3

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.

ericw31415

Posted 2016-12-30T17:30:07.313

Reputation: 2 229

beat me by 1 byte.. :( – devRicher – 2016-12-30T18:23:05.430

@devRicher But I haven't exactly golfed mine yet. :) – ericw31415 – 2016-12-30T18:39:50.047

@devRicher Actually I accidentally miscounted the newline. Whoops. Edit: I've beat you now. – ericw31415 – 2016-12-30T18:44:16.207

1@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)).joinBACKTICK NEWLINE BACKTICK;') – user2428118 – 2016-12-30T20:55:32.690

@user2428118 This doesn't work? I can use your array simplification though. :) – ericw31415 – 2016-12-31T22:41:07.333

You can replace b=[...b,...a.slice(1)] by b.push(...a.slice(1)) to save 1 byte. – Florent – 2017-01-02T09:11:22.960

3

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!

Dennis

Posted 2016-12-30T17:30:07.313

Reputation: 196 637

It looks like the lines don't alternate directions in your test case. – xnor – 2016-12-31T01:02:04.207

It looks like a [_::3] would be shorter. – xnor – 2016-12-31T01:17:35.547

Oh shoot, something went wrong there. Deleting until I can fix it. – Dennis – 2016-12-31T01:19:35.803

That fixed my code without adding any bytes. Thanks! Let's see if I manage to deduplicate those lines again. – Dennis – 2016-12-31T01:34:03.960

There's 2**n%5%3 which cycles [1, 2, 1, 0, 1, 2, 1, 0, ...]. Might that be useful? – xnor – 2016-12-31T03:06:24.590

I think that would be the same byte count. I tried -~n**3%4 before. – Dennis – 2016-12-31T03:08:40.823

3

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.

xnor

Posted 2016-12-30T17:30:07.313

Reputation: 115 687

2

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.

devRicher

Posted 2016-12-30T17:30:07.313

Reputation: 1 609

2

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>

edc65

Posted 2016-12-30T17:30:07.313

Reputation: 31 086

1

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

Timtech

Posted 2016-12-30T17:30:07.313

Reputation: 12 038

Also, before you suggest it, GML requires each part of the for loop to have a statement inside :( – Timtech – 2016-12-30T19:44:50.287

1

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.

Dennis

Posted 2016-12-30T17:30:07.313

Reputation: 196 637

0

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);
}

Steadybox

Posted 2016-12-30T17:30:07.313

Reputation: 15 798

Nice to see another answer in C, but it can be done quite a bit shorter, see my answer :) – orlp – 2016-12-30T20:53:01.513

0

Tcl, 91 bytes

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

Try it online!

sergiol

Posted 2016-12-30T17:30:07.313

Reputation: 3 055

Do I need the put the input part? To account for the byte count? – sergiol – 2017-01-04T03:00:32.657

0

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)

TheLethalCoder

Posted 2016-12-30T17:30:07.313

Reputation: 6 930

0

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!

Dwayne Slater

Posted 2016-12-30T17:30:07.313

Reputation: 111

0

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 (⊂)

ren

Posted 2016-12-30T17:30:07.313

Reputation: 189

0

PowerShell, 64 bytes

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

Try it online!

mazzy

Posted 2016-12-30T17:30:07.313

Reputation: 4 832