ハッピーベーコンデー!


40

今日はベーコンの日で、おそらく今日参加するための帽子の名前は「Mmmm Bacon」です。ベーコンで作られた楽しい2Dマトリックスで、ベーコンの日を祝うのにこれほど素晴らしい方法はありません!1 x 1のベーコンストリップは次のように表されます。

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

ここでの目標は、タプルの2つの座標(xy)を与えられ、ここでxyはゼロ以外の正の整数です。ベーコンを作成し、何らかの形式(リスト、配列、文​​字列)で返します。

入出力:

Input: (2, 1)

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

Input: (1, 2)

Output:

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

Input: (2, 2)

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

ルール:

  • 2番目のテストケースでわかるように、複数のベーコンが積み重ねられている場合、-----各ベーコンが上下に分かれているのは1つだけです。つまり、このようなベーコンの積み重ねは無効です。

    ----- 
    )===)
    (===(
    )===)
    -----
    ----- 
    )===)
    (===(
    )===)
    -----   
    
  • 標準的な抜け穴は禁止されています

  • 上記テストケースのコード必須の作業と次(4, 4)(1, 6)(5, 1)(2, 3)(3, 2)

  • 上記のテストケースをテストできるインタープリターを提供する

受賞基準:

最短のコードが勝ちます!みんなにハッピーベーコンデー!


回答:


11

V28、26、24のバイト

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

オンラインでお試しください!

説明:

À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

3
この答えがベーコンよりも3バイトしか長くないのが大好きです:D
FlipTack

3
@FlipTack改行があります。実際には2つ短くなっています。:P
DJMcMayhem

2
それを忘れました!うわー、出力の構成要素よりも短い答え。これはいくつかのデニススタイルのものです。
FlipTack 16

8

TI-Basic、80バイト

これは実際にはかなり天才でした:)

":→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

また、TI-Basicでは、コロンと改行は互換性があり、Input引数なしで使用すると、デフォルトでXandに入力されますY
ティムテック16

7

Python 2.7、74バイト

私はこれがもう少しゴルフできると確信していますが、これは私が思いついたものです(Pythonの文字列乗算機能は確かに便利です):

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

ここで試してみてください

説明のないゴルフ:

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!

5

Mathematica、74バイト

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

2つの正の整数引数を取り、string-with-newlinesを返す名前のない関数。Mathematicaの標準的なアプローチ:(mod 4)セレクターを使用して文字列の2次元配列を作成し、文字列を垂直方向に循環させてから、単一の文字列に折りたたみます。


4

バッチ、168バイト

@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:_=-%

むしろ残念ながら、@echo %s:==-%そうしないと2番目の変数が不要になります。


行1、2、および3,4を&...で連結して2バイト節約します。
Magoo

4

C、91 89バイト

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

4

05AB1E、25バイト

コード:

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

説明:

…)==û                         # 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

CP-1252エンコードを使用します。オンラインでお試しください!


4

05AB1E32 30バイト

Adnanのおかげで2バイト節約できました。

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

オンラインでお試しください!

説明

'-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

あなたは置き換えることができます")===)"によって…)==û:)
アドナン・

@アドナン:もちろんです!ありがとう!
エミグナ16

3

Python 2、70バイト

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

4バイトを節約してくれた@xnorに感謝します!

オンラインでお試しください!


テストケースでは、線が方向を変えないように見えます。
xnor 16

a [_::3]が短くなるようです。
XNOR

ああ、そこで何かがうまくいかなかった。修正できるまで削除します。
デニス

これにより、バイトを追加せずにコードが修正されました。ありがとう!これらの行を再度重複排除できるかどうかを確認しましょう。
デニス

2**n%5%3サイクルがあり[1, 2, 1, 0, 1, 2, 1, 0, ...]ます。役に立つかもしれませんか?
xnor 16

3

Python 2、59バイト

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

a+b*3+a初期文字aと中心文字b(から計算されるa)から各行を生成します。aサイクルを介して'-()('、一方、bある'-'場合aであり'-'、そして'='そうでありません。


67バイト:

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

その外側の文字からそれぞれライン生成a中心文字bとしてa+b*3+a次に印刷、w本のコピーが。を介してこれらのサイクルzip


3

JavaScript、132 129 121バイト

@ user2428118のおかげで-8バイト

(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`')

これはおそらくもっとゴルフできるでしょう。提案があれば、コメントに残してください。


私を1バイト倒した。:(
devRicher

@devRicherしかし、私はまだ正確にゴルフをしていません。:)
ericw31415 16

@devRicher実際、私は誤って改行を誤って数えました。おっと。編集:私は今あなたを倒した。
ericw31415 16

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)).join_BACKTICK NEWLINE BACKTICK_;')
user2428118

@ user2428118これは機能しませんか?ただし、配列の単純化を使用できます。:)
ericw31415 16


2

JavaScript(ES6)、78

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

テスト

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>


1

GameMaker言語、160 139 148バイト 133バイト

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

また、提案する前に、GMLではforループの各部分にステートメントを
含める

1

ゼリー、26バイト

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

これは、2D配列を返すダイアディックリンク(関数)です。

オンラインでお試しください!

使い方

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.

0

C、159 158 153バイト

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

で呼び出す:

int main()
{
    b(2,3);
}

Cで別の答えを見るのはいいですが、かなり短くすることができます、私の答えを参照してください:)
orlp

0

C#、160バイト

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

フォーマット済みバージョン:

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

オンラインでお試しください!(何らかの理由でこのリンクはエラーになりますが、とにかく動作します)



0

Dyalog APL、55バイト

Dyalog APLを使用するのはこれが初めてなので、これは最良のアプローチではないと確信しています。

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

説明:これは非常に単純なアプローチです。N×Mのベーコングリッドに対して、次の4つの文字列のN×(4M)マトリックスを作成し、繰り返します。

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

次に、文字列-----を先頭に連結します。

コードの簡単な説明を次に示します。

')===)' '(===(' ')===)' '-----'  ⍝ 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 (⊂)


弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.