私をもう少しにしてください!


19

もっと私を作ってください!幅、グラハムクラッカーの量、チョコレートの量、マシュマロの量を教えてください。例:

入力:

幅:10 グラハム:3 チョコレート:2 マシュマロ:1

出力:

GGGGGGGGGG
GGGGGGGGGG
GGGGGGGGGG
CCCCCCCCCC
CCCCCCCCCC
MMMMMMMMMM
GGGGGGGGGG
GGGGGGGGGG
GGGGGGGGGG

それは簡単なこと?ええと...はい。

入力は、文字列ではなく、関数またはプログラムの引数のリストである必要があることに注意してください。最初にWidthを選択し、次にGrahamを選択できますが、順序は任意です。

興味がある場合は、完全なテストケース。

スタックスニペット(テスト用など)

これは、出力をテストするためです。

var smore = function(width, graham, chocolate, marshmallow){
	return ("G".repeat(width) + "\n").repeat(graham) + 
	("C".repeat(width) + "\n").repeat(chocolate) + 
	("M".repeat(width) + "\n").repeat(marshmallow) + 
	("G".repeat(width) + "\n").repeat(graham);
};
Snippetify(smore);
<script src="https://programmer5000.com/snippetify.min.js"></script>
Width: <input type = "number">
Graham: <input type = "number">
Chocolate: <input type = "number">
Marshmallow: <input type = "number">
<button>Try it out!</button>
<pre data-output></pre>

ノート:

  • 最後の行の末尾に末尾の改行を含めることができます。\改行の代わりにを使用することもできます。
  • これはです。
  • 質問は?以下のコメント:

21
Let Me Google That For Youリンクを編集しました。本当に面白くなかった。
レベルリバーセント

1
@FelipeNardiBatistaはい。
Programmer5000

1
いくつかの答えは、柔軟な入力順序とフォーマット(PPCGでの通常)を想定していますが、課題には特定の順序が必要で、文字列を除外しているようです(意味はわかりません)。明確にできますか?
ルイスメンドー

2
明確にしてくれてありがとう。次に、入力を文字列ではなく、関数またはプログラムへの引数のリストにする必要があり、最初に幅、次にグラハムなどの文を書き直す必要があります。個人的に私は、「入力フォーマットは、いつものように柔軟である」のようなものだと思います
ルイスMendo

4
@ programmer5000しかし、なぜですか?彼らがダウン投票した場合、それは彼らが退屈で些細な挑戦だと思うからです。さらに、人々に説明や撤回を命じることは非常に失礼です。彼らはコメントなしで下票する権利を持っています。
Rɪᴋᴇʀ

回答:


2

ゼリー、11バイト

ṁ4“GCMG”x×Y

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

使い方

ṁ4“GCMG”x×Y  Main link. Left argument: g, c, m. Right argument: w

ṁ4           Mold 4; repeat g, c, m until length 4 is reached. Yields [g, c, m, g].
  “GCMG”x    Repeat 'G' g times, then 'C' c times, then 'M' m times, and finally
             'G' g times. This yields a string.
         ×   Multiply each character w times. This is essentially a bug, but
             Jelly's × behaves like Python's * (and vectorizes), so it can be
             abused for character repetition.
          Y  Join, separating by linefeeds.


8

05AB1E21 19 19バイト

"GCMG"S×|D«‚øvy`.D»

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

-2私の監督とエミニャに感謝します。

"GCMG"S×            # Push GCMG, separate, duplicate n times.
        |D«         # Push rest of inputs, doubled.
           ‚ø       # Wrap GCMG array and input array, then zip them into pairs.
             vy`.D» # For each pair, print n of G/C/M/G.

(エミグナの答えを参照してください、それは良いです:https ://codegolf.stackexchange.com/a/116787/59376 )


1
あなたが誤っ©てそこに残したようです。
エミグナ

1
zipすると余分な要素が失われるため¬¸、と置き換えることもできDます。
エミグナ

@Emigna私はその機能が好きでも嫌いでもあります。
魔法のタコUr

はい、それはしばしば非常に迷惑ですが、
時々

8

JavaScript(ES6)、71バイト

(W,G,C,M)=>[...'GCMG'].map(X=>`${X.repeat(W)}
`.repeat(eval(X))).join``

Woohoo、他の3つのJavaScriptの答えを破りました!


ナイス、とてもナイス-私の票を得る。
シャギー

7

MATL、17バイト

'GCMG'iK:)Y"!liX"

入力形式は[G, C, M]、最初の入力、2番目の入力Wです。

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

例付きの説明

入力[3 2 1] とを検討してください10

'GCMG' % Push this string
       % STACK: 'GCMG'
i      % Take first input: array of three numbers
       % STACK: 'GCMG', [3 2 1]
K:     % Push [1 2 3 4]
       % STACK: 'GCMG', [3 2 1], [1 2 3 4]
)      % Index (modular, 1-based). This repeats the first entry of the input array
       % STACK: 'GCMG', [3 2 1 3]
Y"     % Run-length decoding
       % STACK: 'GGGCCMGGG'
!      % Transpose. Gives a column vector of chars
       % STACK: ['G'; 'G'; 'G'; 'C'; 'C'; 'M'; 'G'; 'G'; 'G']
l      % Push 1
       % STACK: ['G'; 'G'; 'G'; 'C'; 'C'; 'M'; 'G'; 'G'; 'G'], 1
i      % Take second input: number
       % STACK: ['G'; 'G'; 'G'; 'C'; 'C'; 'M'; 'G'; 'G'; 'G'], 1, 10
X"     % Repeat the specified numbers of times along first and second dimensions
       % STACK: ['GGGGGGGGGG';'GGGGGGGGGG';'GGGGGGGGGG';'CCCCCCCCCC';...;'GGGGGGGGGG']
       % Implicitly display

7

C#、204バイト


ゴルフ

(w,g,c,m)=>{string G="\n".PadLeft(++w,'G'),C="\n".PadLeft(w,'C'),M="\n".PadLeft(w,'M'),o="".PadLeft(g,'G');o+="".PadLeft(m,'M')+"".PadLeft(c,'C')+o;return o.Replace("G",G).Replace("C",C).Replace("M",M);};

非ゴルフ

( w, g, c, m ) => {
   string
      G = "\n".PadLeft( ++w, 'G' ),
      C = "\n".PadLeft( w, 'C' ),
      M = "\n".PadLeft( w, 'M' ),
      o = "".PadLeft( g, 'G' );

   o +=
      "".PadLeft( m, 'M' ) +
      "".PadLeft( c, 'C' ) +
      o;

   return o
      .Replace( "G", G )
      .Replace( "C", C )
      .Replace( "M", M );
};

読みやすい

// Function with 4 parameters
//   w : Width
//   g : Graham
//   c : Chocolate
//   m : Marshmallow
( w, g, c, m ) => {

   // Initialization of vars with the contents
   //    of each line, with a new line at the end
   string
      G = "\n".PadLeft( ++w, 'G' ),
      C = "\n".PadLeft( w, 'C' ),
      M = "\n".PadLeft( w, 'M' ),

      // Trick to reduce the byte count
      //   Initialize the output with n 'G's
      o = "".PadLeft( g, 'G' );

   // Add again n 'M's and n 'C's
   //   Append the 'G's at the end.
   o +=
      "".PadLeft( m, 'M' ) +
      "".PadLeft( c, 'C' ) +
      o;

   // Replce every instance of 'G'/'C'/'M'
   //    with the full line
   return o
      .Replace( "G", G )
      .Replace( "C", C )
      .Replace( "M", M );
};

完全なコード

using System;
using System.Collections.Generic;

namespace Namespace {
   class Program {
      static void Main( String[] args ) {
         Func<Int32, Int32, Int32, Int32, String> f = ( w, g, c, m ) => {
            string
               G = "\n".PadLeft( ++w, 'G' ),
               C = "\n".PadLeft( w, 'C' ),
               M = "\n".PadLeft( w, 'M' ),
               o = "".PadLeft( g, 'G' );

            o +=
               "".PadLeft( m, 'M' ) +
               "".PadLeft( c, 'C' ) +
               o;

            return o
               .Replace( "G", G )
               .Replace( "C", C )
               .Replace( "M", M );
         };

         List<Tuple<Int32, Int32, Int32, Int32>>
            testCases = new List<Tuple<Int32, Int32, Int32, Int32>>() {
               new Tuple<Int32, Int32, Int32, Int32>( 1, 1, 1, 1 ),
               new Tuple<Int32, Int32, Int32, Int32>( 1, 1, 1, 2 ),
               new Tuple<Int32, Int32, Int32, Int32>( 1, 1, 2, 1 ),
               //
               // ...
               //
               // The link above contains the code ready to run
               //    and with every test from the pastebin link
               //
               // Yes, it contains 342 tests ready to run.
               //
               // I can barely fit every test on a 1080p screen...
               //    ... and there's 6 tests per line... Jebus...
               //
            };

         foreach( var testCase in testCases ) {
            Console.WriteLine( $"Input:\nWidth: {testCase.Item1,3} Graham: {testCase.Item2,3} Chocolate: {testCase.Item3,3} Marshmellow: {testCase.Item4,3}\nOutput:\n{f( testCase.Item1, testCase.Item2, testCase.Item3, testCase.Item4 )}\n" );
         }

         Console.ReadLine();
      }
   }
}

リリース

  • v1.0の - 204 bytes-初期ソリューション。

ノート


感謝!:D
auhmaan

7

05AB1E17 16バイト

carusocomputingのおかげで1バイト節約されました。

"GCMG"S×vy²Nè.D»

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

入力順は W, [G,C,M]

説明

10, [3,2,1] 例として使用。

"GCMG"S           # push the list ['G','C','M','G']
       ×          # repeat each W times
                  # STACK: ['GGGGGGGGGG', 'CCCCCCCCCC', 'MMMMMMMMMM', 'GGGGGGGGGG']
        v         # for each [string, index] y,N in the list
          ²Nè     # get the amount of layers at index N from the [G,C,M] list
         y   .D   # duplicate the string y that many times
               »  # join strings by newlines

1
"GCMG"S×vy²Nè.D»ワンダーツインパワー、アクティベート!05AB1Eコードの形式!また、引数が交換されますが、それはまだ16だ
マジックタコ壺

@carusocomputing:印刷されていないがらくたをスタックに残さないという利点がありますが、私には同じように還元できないようです。
エミグナ

1
まだ1バイト少なく、MATLでネクタイに勝ちます;)。
魔法のタコUr

@carusocomputing:ああ、いつ起きたの?私はそれを見たときに17だったと確信していた。いいね!;)
エミグナ

馬鹿になっていることに気付いてから1分後に、愚かなものを投稿して編集することがよくあります。
魔法のタコUr

6

ルビー、47バイト

->w,g,c,m{puts r=[?G*w]*g,[?C*w]*c,[?M*w]*m,r}

ベンテロのおかげで

Ruby、51バイト

->w,g,c,m{(?G*g+?C*c+?M*m+?G*g).chars{|i|puts i*w}}

このような呼び出し:

f=->w,g,c,m{(?G*g+?C*c+?M*m+?G*g).chars{|i|puts i*w}}

f[10,3,2,1]

->w,g,c,m{puts r=[?G*w]*g,[?C*w]*c,[?M*w]*m,r}少し短い
Ventero

5

PowerShell、49バイト

$a,$b=$args;0..2+0|%{,("$('GCM'[$_])"*$a)*$b[$_]}

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

入力を4つのコマンドライン引数として受け取りwidth graham chocolate marshmallow、最初を$a残りを$b(暗黙的に配列として)に格納します。範囲を超えてループします0,1,2,0。各ループは、string GCMにインデックスを付け、それを文字列として再キャストしchar、それを$a(幅)で乗算し、次にカンマ演算子を使用,して、適切なインデックス$b(つまり、いくつのレイヤー)。これらの結果の文字列配列はすべてパイプラインに残され、出力は暗黙的で、要素間に改行があります。



4

バッチ、146バイト

@set s=
@for /l %%i in (1,1,%1)do @call set s=G%%s%%
@for %%w in (%2.%s% %3.%s:G=C% %4.%s:G=M% %2.%s%)do @for /l %%i in (1,1,%%~nw)do @echo%%~xw

4つのループをネストされたループに折りたたむために、エコーするテキストとechoその間のシンボルをしばしば無視できるという点で、あいまいな動作に依存していechoます。


4

V、22バイト

éGÄÀäjMoC
MÀÄkÀÄHdêÀP

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

Hexdump:

00000000: e947 c4c0 e46a 4d6f 430a 4d1b c0c4 6bc0  .G...jMoC.M...k.
00000010: c448 64ea c050                           .Hd..P

入力順は

Graham, Marshmallow, Chocolate, Width

説明:

éG                  " Insert 'G'
  Ä                 " Duplicate this line
   Àäj              " *arg1* times, duplicate this line and the line below it
      M             " Move to the middle line
       o            " Open up a newline, and enter insert mode
        C<cr>M<esc> " Insert 'C\nM'
ÀÄ                  " Make *arg2* copies of this line (Marshmallow)
  k                 " Move up one line
   ÀÄ               " Make *arg3* copies of this line (Chocolate)
     H              " Move to the first line
      dê            " Delete this column
        ÀP          " And paste it horizontally *arg4* times

説明を追加してもらえますか?
Programmer5000

@ programmer5000もちろん!編集内容を見る
DJMcMayhem

4

Excel、104バイト

ああ少年!改行が必要な数式。

=REPT(REPT("G",A1)&"
",A2)&REPT(REPT("C",A1)&"
",A3)&REPT(REPT("M",A1)&"
",A4)&REPT(REPT("G",A1)&"
",A2)

A1
A2にグラハム
A3にチョコレート
A4にマローがあります


事前フォーマットが許可されている場合、セルを垂直テキスト用にフォーマットし、式を65バイトに短縮できます。

=REPT(REPT("G",A2)&REPT("C",A3)&REPT("M",A4)&REPT("G",A2)&"
",A1)

4

ゼリー、13 バイト

“GCM”ẋ"ṁ4Fẋ€Y

ダイアディックプログラム。入力は次のとおり[Graham's, Chocolates, Marshmallows]ですWidth

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

どうやって?

“GCM”ẋ"ṁ4Fẋ€Y - Main link: [g,c,m], w    e.g. [1,2,1], 2
“GCM”         - literal ['G', 'C', 'M']
      "       - zip that and [g,c,m] with the dyadic operation:
     ẋ        -     repeat list               [['G'],['C','C'],['M']]
       ṁ4     - mould like [1,2,3,4]          [['G'],['C','C'],['M'],['G']]
         F    - flatten                       ['G','C','C','M','G']
          ẋ€  - repeat €ach w times           [['G','G'],['C','C'],['C','C'],['M','M'],['G','G']]
            Y - join with line feeds          ['G','G','\n','C','C','\n','C','C','\n','M','M','\n','G','G']
              - implicit print                GG
                                              CC
                                              CC
                                              MM
                                              GG

3

PHP、85バイト

for($m=$argv;$i++<4;)for($c=$m[_2342[$i]]*$m[1];$c;)echo$c--%$m[1]?"":"\n",_GCMG[$i];

または

for($m=$argv;$i++<4;)for($c=$m[_2342[$i]];$c--;)echo"\n".str_pad("",$m[1],_GCMG[$i]);

オンライン版

PHP、96バイト

<?[$n,$w,$G,$C,$M]=$argv;for(;$i<4;$i++)for($t=${"$n[$i]"};$t--;)echo"\n".str_pad("",$w,$n[$i]);

オンライン版

拡大

[$n,$w,$G,$C,$M]=$argv; # $argv[0] must contain a file beginning with "GCMG"
for(;$i<4;$i++) # Take the first 4 values of the filename
for($t=${"$n[$i]"};$t--;) # How many rows should be printed
echo"\n".str_pad("",$w,$n[$i]); # print $w times the actual letter

3

05AB1E、14バイト

コード:

…GCM‚øü׬)˜S×»

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

説明:

…GCM              # Push the string "GCM"
    ‚             # Wrap with the input
     ø            # Transpose the array
      ü×          # Compute the string product of each element (['A', 3] --> 'AAA')
        ¬)˜       # Get the last element and append to the list
           S      # Split the list
            ×     # Vectorized string multiplication with the second input
             »    # Join by newlines and implicitly print

3

Python 26757バイト

(編集:マトリックスが許可され、改行結合する必要がなくなりました。)

def s(w,g,c,m):g=['G'*w]*g;print g+['C'*w]*c+['M'*w]*m+g

3

C#(150バイト)

void S(int w,int g,int c,int m){P(w,g,'G');P(w,c,'C');P(w,m,'M');P(w,g,'G');}void P(int w,int i,char c){while(i-->0)Console.Write("\n".PadLeft(w,c));}

ゴルフをしていない:

void SMores(int w, int g, int c, int m)
{
    Print(w,g,'G');
    Print(w,c,'C');
    Print(w,m,'M');
    Print(w,g,'G');
}
void Print(int w, int i, char c)
{
    while(i-->0)
        Console.Write("\n".PadLeft(w,c));
}

3

Java、138バイト

String s(int w,int g,int c,int m){String b="";int i=-g-c,j;for(;i++<g+m;){for(j=0;j++<w;)b+=i<=-c|i>m?'G':i<=0?'C':'M';b+="\n";}return b;}

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

説明:

String s(int w, int g, int c, int m) {
    String b = "";
    int i = -g - c, j;              // i is the layer
    for (; i++ < g + m;) {          // Repeat (G+C+M+G) times, starting from -g-c to m+g 
                                    //Layer 0 is the last chocolate layer

        for (j = 0; j++ < w;) {     // Repeat W times
            b += 
                i <= -c | i > m ? 'G': //If before the chocolate or after the marshmellow, output a G
                i <= 0 ? 'C' :      // Else if equal or before last chocolate layer output C
                'M';                //Otherwise output an M
        }
        b += "\n";
    }
    return b;
}


3

SWIFT、138 137 134 130バイト

@Kevinのおかげで7バイト節約

let f=String.init(repeating:count:)
let r={w,g,c,m in f(f("G",w)+"\n",g)+f(f("C",w)+"\n",c)+f(f("M",w)+"\n",m)+f(f("G",w)+"\n",g)}

期待値を返す2つの関数:fはヘルパー関数でありr、出力を生成する実際のlamdbaのような関数です。使用法: print(r(10,3,2,1))

見てみな!


文字列初期化子を直接参照するだけで、いくつかの文字を保存できます(var f=String.init(repeating:count:);)。そして、それはあなたのキャラクターを救いませんが、それは費用がかかりませんので、彼らは両方が本当にあるべきletです。
ケビン

そして、3以上で明示的に引数をドロップすることによってrlet r={f(f("G",$0)+"\n",$1)+f(f("C",$0)+"\n",$2)+f(f("M",$0)+"\n",$3)+f(f("G",$0)+"\n",$1)}
ケビン

おかげで@Kevin、私はあなたがこのような何かに値を初期化することができることは思いもしませんでした:f=String.init(repeating:count:)...
ミスターXcoder

それはあなたの第二の提案に来るとき、それはUTF-8のバイト数を超えているように、それはTIOのバイト数をチェックし、そうです、なぜ知らない@Kevin
氏Xcoder


2

JavaScript(ES6)、91バイト

末尾の改行を含みます。

f=

(w,g,c,m)=>(b=(`G`[r=`repeat`](w)+`
`)[r](g))+(`C`[r](w)+`
`)[r](c)+(`M`[r](w)+`
`)[r](m)+b

console.log(f(10,3,2,1))


2

JS(ES6)、87バイト

x=(w,g,c,m)=>(f=>f`Gg`+f`Cc`+f`Mm`+f`Gg`)(([[x,y]])=>(x.repeat(w)+`
`).repeat(eval(y)))

xスタンドアロンのラムダ関数として機能します。結果には、末尾に改行があります。

スニペットで試してください:


2

C、90バイト(Steadyboxの回答に基づく)

変数の名前を変更し、文字列化プリプロセッサ演算子を利用して、マクロパラメータを削減しました。私はそれ自身の答えが素晴らしいので、このアイデアを投稿したいと思います:)

#define F(x)for(i=x;i--;puts(""))for(j=w;j--;)printf(#x);
i,j;f(w,G,C,M){F(G)F(C)F(M)F(G)}

TIOリンク


賛成票を投じますが、投票制限に達しました:(
Programmer5000

2

F#(148 99バイト)

let s w q="GCMG"|>Seq.iteri(fun i c->for j in 1..(q|>Seq.item(i%3))do printf"%A"("".PadLeft(w,c)))

使用法:

s 10 [2;3;4]

ゴルフをしていない:

let smores width quantities =
    "GCMG"
    |>Seq.iteri(fun i char ->
        for j in 1..(quantities|>Seq.nth(i%3))
            do printf "%A" ("".PadLeft(width,char))) 

私はまだF#が初めてなので、変なことや愚かなことをした場合はお知らせください。


F#へのリンクがいいでしょう。
Programmer5000

2

JavaScriptのES6、69の 68 66バイト

@Arnauldが1バイトのゴルフをしてくれてありがとう

a=>b=>"GCMG".replace(/./g,(c,i)=>`${c.repeat(a)}
`.repeat(b[i%3]))

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

説明

カリー形式で入力を受け取ります (Width)([Graham,Chocolate,Marshmallow])

を使用.replace(/./g,...)すると、文字列内の各文字がGCMG関数からの戻り値に置き換えられます(c,i)=>`${c.repeat(a)} `.repeat(b[i%3])

`${c.repeat(a)} `グラハムクラッカーの各行を作成し、改行を追加して.repeat(b[i%3])、この行を必要な回数繰り返します


を使用replace()すると、バイトが節約されますa=>"GCMG".replace(/./g,(c,i)=>`${c.repeat(a[0])}\n`.repeat(a[1+i%3]))
。– Arnauld

1

JS(ES6)、111バイト

n=`
`,G="G",C="C",M="M",r=(s,t)=>s.repeat(t),(w,g,c,m)=>r(r(G,w)+n,g)+r(r(C,w)+n,c)+r(r(M,w)+n,m)+r(r(G,w)+n,g)

1

Mathematica 102バイト(100文字)

組み込みのスモアがV12まで出てこないことを聞いた。

s=StringRepeat;StringReplace[s@@@({Characters@"GCMG",#/.#[[4]]->#[[1]]})<>"",x_:>x~s~#[[4]]<>"\n"]&

最初に列を構築するというアイデアを使用すると、非常に簡単です。長い関数名は35バイトを無駄にします。1つの箱に見えるシンボルは実際には転置文字であり、Mathematicaにうまく貼り付けられます。

使用法: %@{Graham, Chocolate, Marshmallows, Width}%@{3, 2, 1, 11}


1

Java 7、226バイト

String c(int w,int g,int c,int m){return x(w,'G',g)+x(w,'C',c)+x(w,'M',m)+x(w,'G',g);}String x(int w,char c,int x){String r="";for(;x-->0;r+=x(w,c));return r;}String x(int w,char c){String r="";for(;w-->0;r+=c);return r+"\n";}

または(226バイトも):

String c(int w,int g,int c,int m){return x(w,71,g)+x(w,67,c)+x(w,77,m)+x(w,71,g);}String x(int...a){String r="";for(;a[2]-->0;r+=x(a[0],(char)a[1]));return r;}String x(int w,char c){String r="";for(;w-->0;r+=c);return r+"\n";}

説明:

String c(int w,int g,int c,int m){  // Main method with four integer parameters and String return-type
  return x(w,'G',g)                 //  Return all Graham-rows
        +x(w,'C',c)                 //   plus all Chocolate-rows
        +x(w,'M',m)                 //   Plus all Marshmallon-rows
        +x(w,'G',g);                //   Plus all Graham-rows again
}                                   // End of main method

String x(int w,char c,int x){       // Separate method (1) with two integers & character parameters and String return-type
  String r="";                      //  Result-String
  for(;x-->0;                       //  For the given amount of rows of a certain type
             r+=x(w,c)              //   Append the result-String with a row of the given character
  );                                //  End of for-loop (implicit / no body)
  return r;                         //  Return the result-String
}                                   // End of separate method (1)

String x(int w,char c){             // Separate method (2) with integer and character parameters and String return-type
  String r="";                      //  Result-String
  for(;w-->0;                       //  For the amount given as width
             r+=c                   //   Append the character to the row
  );                                //  End of for-loop (implicit / no body)
  return r+"\n";                    //  Return the result-String including a new-line
}                                   // End of separate method (2)

テストコード:

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

class M{
  String c(int w,int g,int c,int m){return x(w,'G',g)+x(w,'C',c)+x(w,'M',m)+x(w,'G',g);}String x(int w,char c,int x){String r="";for(;x-->0;r+=x(w,c));return r;}String x(int w,char c){String r="";for(;w-->0;r+=c);return r+"\n";}

  public static void main(String[] a){
    System.out.print(new M().c(10,3,2,1));
  }
}

出力:

GGGGGGGGGG
GGGGGGGGGG
GGGGGGGGGG
CCCCCCCCCC
CCCCCCCCCC
MMMMMMMMMM
GGGGGGGGGG
GGGGGGGGGG
GGGGGGGGGG

1
悪くない... java!
Programmer5000

1
@ programmer5000 Hehe、ありがとう!私のJava 7でのゴルフ(時には8)のように、私はそれが今までにも他の回答と競合するとは思いませんが... Javaの答えと「やや競っ」だけ時間がしていました。この8バイトの解答、この19バイトの回答、実際に初めてPythonを凌ぐ。; p 1バイトまたは2バイトの提出を伴うこれらのゴルフ言語は、もちろんJavaをほこりのままにします。
ケビンCruijssen

1

Haskell、91バイト

import Data.List
(#)=replicate
f w g c m=intercalate"\n"$map(w#)$g#'G'++c#'C'++m#'M'++g#'G'

かなり自明なはずです。コメントで文字行列が許可されていることが指摘されているため、文字列のリスト(各レイヤーに1つ)を返す58バイトバージョンを次に示します。

(#)=replicate
f w g c m=map(w#)$g#'G'++c#'C'++m#'M'++g#'G'
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.