# Make me a s'more!

Make me a s'more! I tell you the width, the amount of graham cracker, the amount of chocolate, and the amount of marshmallow. An example:

Input:

Width: 10 Graham: 3 Chocolate: 2 Marshmallow: 1.

Output:

GGGGGGGGGG
GGGGGGGGGG
GGGGGGGGGG
CCCCCCCCCC
CCCCCCCCCC
MMMMMMMMMM
GGGGGGGGGG
GGGGGGGGGG
GGGGGGGGGG


Is it that easy? Um... yes.

Note that the input should be a list of arguments to a function or a program, not a string. You might choose the first being Width, then Graham, but any order is fine.

Full test cases if you are interested.

# Stack snippet (for testing, etc.)

This is to test the output.

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>

# Notes:

• You may include a trailing newline on the end of the last line. You may also use a \ instead of a newline.
• This is .
• Any questions? Comment below:
• I edited out your Let Me Google That For You link. It really wasn't funny. – Level River St Apr 17 '17 at 13:47
• @FelipeNardiBatista yes. – programmer5000 Apr 17 '17 at 14:30
• Some answers are assuming flexible input order and format (as usual in PPCG), but the challenge seems to require a specific order and rule out strings (not sure what that means). Can you clarify? – Luis Mendo Apr 17 '17 at 14:34
• Thanks for clarifying. You should then reword the sentence the input should be a list of arguments to a function or a program, not a string, with the first being Width, then Graham, etc. Personally I would say something like "Input format is flexible as usual" – Luis Mendo Apr 17 '17 at 14:36
• @programmer5000 but why? If they downvoted, it's 90% likely it's because they think it's a boring and trivial challenge. Furthermore, it's quite rude to tell people to explain or retract. They have the right to downvote without comment. – Rɪᴋᴇʀ Apr 17 '17 at 16:12

## R, 117 114 bytes

f=function(w,g,h,m){s=strrep;f=function(a,b)s(paste0(s(a,w),'\n'),b);G=f("G",g);cat(G,f("C",h),f("M",m),G,sep='')}


Explanation:

function(w,g,h,m){              #width, graham, chocolate, marshmallow
s=strrep                      #repeats strings (for each layer)
f=function(a,b){              #for a given layer
s(paste0(s(a,w),'\n'),b)    #repeat the corresponding letter w times, then repeat that + a newline the corresponding number of times
}
G=f("G",g)
cat(                        #print to console:
G,                 #so repeat "G" w times, over g lines
f("C",h),                 #etc.
f("M",m),
G,sep='')        #with no separation
}


Saved 3 bytes thanks to @Giuseppe!

• This can be shortened to 97 bytes with a different approach: function(w,g,s,m)matrix(c(rep("G",w*g),rep("S",w*s),rep("M",w*m),rep("G",w*g)),g*2+s+m,w,byrow=T) – count Apr 19 '17 at 7:25
• That seems to output a matrix, which doesn't quite look like what the OP specified. – BLT Apr 19 '17 at 12:52
• Removing the brackets throws an error, but great catch on the 3 bytes! – BLT Apr 19 '17 at 20:59

# Japt, 30 26 bytes

"GCMG"¬mpU £XÄ pVgY)q1Ãm·q


Try it online!

30-byte solution:

Y=VÆ'GpUÃ·[YWÆ'CpUÃ·XÆ'MpUÃY]·


Try it online!

# T-SQL, 259 bytes

CREATE PROC S @ INT,@g INT,@c INT,@m INT,@b INT=0 AS SET @B=@G G:PRINT REPLICATE('G',@)SET @G-=1IF @G>0 GOTO G C:PRINT REPLICATE('C',@)SET @C-=1IF @C>0GOTO C M:PRINT REPLICATE('M',@)SET @M-=1IF @M>0GOTO M Q:PRINT REPLICATE('G',@)SET @B-=1IF @B>0 GOTO Q RETURN


This stored procedure loops for the first layer or graham, chocolate, and Marshmallow with a GOTO in order to print up to the established amount. For the last layer of graham the fourth optional parameter (previously setted to the @g value) is used to do the same as the first layer of graham. The width of the layer is created with the REPLICATE function.

Usage:

EXECUTE S @ = 5, --Width
@g = 7, --Graham
@c = 8, --Chocolate
@m = 4, --Marshmallow
@b = NULL --Control variable, can be ignored


# Charcoal, 23 bytes

↷²Ｎγ×⟦⁺⁺⁺×Gγ×CＮ×MＮ×Gγ⟧Ｎ


Try it online!

Input is in the form graham, chocolate, marshmallow, width

## Explanation

↷²                          Pivot right by 2 * 45 degrees
Ｎγ                       Input number to g
⟦⁺⁺⁺×Gγ×CＮ×MＮ×Gγ⟧   "G" * g + "C" * input number + "M" * input number + "G" * g
×                   Ｎ Multiplied by N


Lists are implicitly printed joined by newlines.

• I think you can save a byte by inputting ×GＮ to γ and another byte by using ↓ instead of ↷². (Note that the existing code no longer works because × now vectorises but you can concatenate a newline for the same byte count.) – Neil Dec 27 '17 at 21:08

Anonymous Google Sheets worksheet formula that takes input from cells A1,B1,C1,D1 and outputs a s'more to the calling cell

=REPT(REPT("G",A1)&"
",B1)&REPT(REPT("C",A1)&"
",C1)&REPT(REPT("M",A1)&"
",D1)&REPT(REPT("G",A1)&"
",B1


# K (oK), 32 17 bytes

Solution:

{x#',/4#y#'"GCM"}


Try it online!

Example:

> {x#',/4#y#'"GCM"}[10;(3;2;1)]
("GGGGGGGGGG"
"GGGGGGGGGG"
"GGGGGGGGGG"
"CCCCCCCCCC"
"CCCCCCCCCC"
"MMMMMMMMMM"
"GGGGGGGGGG"
"GGGGGGGGGG"
"GGGGGGGGGG")


Explanation:

{x#',/4#y#'"GCM"} / solution
{               } / lambda function with implicit parameters x and y
y#'"GCM"  / take input each-both (#') number "G", "C" and "M"
4#          / 4-take, ("GGG";"CC";"M") -> ("GGG";"CC";"M";"GGG")
,/            / flatten list into string, ("GGG";"CC";"M";"GGG") -> "GGGCCMGGG"
x#'              / width-take each (10#"G" -> "GGGGGGGGGG" etc)


Notes:

• -15 bytes as looking through other answers it seems acceptable to take parameters as [width;(graham;chocolate;marshmallow)], which means I don't have to explicitly list the parameters to the function

# SOGL V0.12, 11 bytes

GCM”{e*.∙Q≥


Try it Here!

Explanation:

GCM”         push "GCM"
{        for each
e*        multiply horizontally by e, which, when first called, gets the numerical value of the next input
.∙      multiply vertically by the nest input
Q     output without popping and without disabling implicit output
≥    put the top item of the stack at the bottom as to keep the first item on the top

• wasn' sogl v0.12 released after this challange? – Felipe Nardi Batista Oct 9 '17 at 13:44
• @FelipeNardiBatista Yes, but that's now allowed. – dzaima Oct 9 '17 at 13:56

# R, 69 bytes

function(n,u)cat(rep(strrep(c("G","C","M","G"),n),c(u,u[1])),sep="
")


Try it online!

Trying this strrep function I just heard about... Probably a intToUtf8 approach could do better than that. Thanks @Shaggy for pointing an issue...fixing it saved 6 bytes.

• There's only one layer of chocolate. – Shaggy Jul 11 '18 at 14:14
• @Shaggy you just saved me 6 bytes, ty! – JayCe Jul 11 '18 at 14:22
• @dzaima it takes a width n and a vector of heights u which you can input as c(g,c,m), like this – Giuseppe Jul 11 '18 at 14:44
• @Giuseppe oh. Really shouldn't ask questions about languages I don't know :p – dzaima Jul 11 '18 at 14:48

# Japt-R, 16 bytes

"GCMG"ËpU*VgEÃòU


Try it

## Explanation

                     :Implicit input of integer U=Width & array V=[Graham,Chocolate,Marshmallow]
"GCMG"               :String literal
Ë              :Map each character at index E
p             :  Repeat
U*           :   U multiplied by
VgE        :   Get the integer at index E in V (Yay, index wrapping!)
Ã       :End mapping
òU     :Split to an array of strings of length U
:Implicitly join with newlines and output


# Canvas, 12 11 bytes

GCMG｛²└＠＊×Ｐ


Try it here!

Explanation:

GCMG     push "GCMG"
{      for each character
²       push the counter.                     Stack: [(input2, input1), "G", 1]
└      swap two items below ToS.             Stack: [(I1, I2), "G", I1, 1]
@     get the counter'th item of the input. Stack: [(I1, I2), "G", I1[1] ]
*    repeat horizontally.                  Stack: [(I1, I2), "G" * I1[1] ]
×   repeat vertically.                    Stack: [(I2, I1), I2 × "G" * I1[1] ]
P  print that.                           Stack: [(I2, I1)]