## Challenge

Code an ASCII cookie of a kind according to the input.

## Input

• The cookie kind. This is one of the three strings: "Plain", "Chocolate", or "Nuts". May be function arguments, stdin (or closest equivalent), or file arguments.

## Output

• An ASCII cookie. See below.

Must be

     ___
/   \
|   |
\___/


for Plain input,

     ___
/. .\
| . |
\___/


for Chocolate input, and finally

     ___
/^  \
|^ ^|
\___/


for Nut input.

## Other information

• This is my first challenge, it's as simple as can be. Constructive feedback is greatly appreciated.
• Use any means to do so.
• Trailing spaces are fine.
• This is a code golf challenge, so shortest entry at the end of 9 days (Wednesday, the 12th of August 2015) wins.

## Thank you!

The winner is Jakube using Pyth with 41 bytes. Thank you to all who participated. I will now task myself with coming up with more complicated challenges.

• This is nice, but rather simple as it is. It could be massively improved by requiring user input for the diameter or quantity of cookies of each type. Do the chocolate chips and and nuts have to be in the location per the examples? (with variable diameter, they could perhaps be random.) That said, it's bad form to change the challenge after posting. I suggest you either 1. leave it as it is, or 2. delete it, think a bit more about it and/or post it in meta.codegolf.stackexchange.com/q/2140/15599 then repost later. Aug 3 '15 at 23:07
• Allowing multiple toppings could have been another way to make this more interesting. Then again, simple looking challenges often get a lot of participation. BTW, two of the cookies have leading white space in the sample output. That's probably not intentional? Aug 3 '15 at 23:14
• I made a minor edit to cancel the indent, so all the cookies have the same leading whitespace. I assume the four leading spaces are a formatting issue and are not required? You should specify whether leading/trailing newlines are allowed. I would suggest disallowing unnecessary whitespace, with the exception of allowing an optional trailing newline. Aug 3 '15 at 23:21
• Will functions be permitted?
– bren
Aug 4 '15 at 1:39
• After @steveverrill opened my eyes, this seems to be just a simplified version of Do you want to code a snowman?. Some further requirements, like the mentioned variable diameter, would really improve it. Aug 4 '15 at 10:36

# Ruby, 73

->s{' ___
/'+['^  \
|^ ^','. .\
| . ','   \
|   '][s[0].ord%3]+'|
\___/'}


This is an anonymous lambda function. Here it is in a test program:

g=->s{' ___
/'+['^  \
|^ ^','. .\
| . ','   \
|   '][s[0].ord%3]+'|
\___/'}

puts g.call(gets)


It just uses the first letter of the cookie type (in uppercase) and takes it modulo 3 to get an index in the range 0..2. Then it returns the string representing the cookie, with the appropriate strings embedded in the right places.

• What do you think the ord method can do if you call it for a whole string? My first idea was formatting: ->s{" ___\n/%1$s \\\n|%1$s %1$s|\n\\___/"%'^. '[s.ord%3]} Aug 4 '15 at 6:32 • Forget it. Once again tr proves to be shorter: ->s{' ___↵/% \↵|% %|↵\___/'.tr ?%,'^. '[s.ord%3]} Aug 4 '15 at 6:39 • @manatwork thank you for your suggestions. I missed s[0] --> s, it never occurred to me to try it. Your code doesn't seem to give the right answer for the chocolate case, as the chocolate chips are in different places than the nuts. Nevertheless there's some useful ideas there, I will look at them later. I haven't used tr or % before. Aug 4 '15 at 10:21 • Oops. You are right. That was a quick try BC (before coffee). Too early to notice the chips placement difference. :( (BTW, the “%” has nothing to do with tr's syntax. Is just a character not involved in the cookie art that I used as placeholder.) Aug 4 '15 at 10:28 # Pyth, 42 41 bytes X" ___ /d a\\ |cac| \___/"G.>"^X . .^"Cz  Try it online: Regular Input / Test Suite ### Explanation:  "..." template string X G replace "a..z" in ^ with: Cz convert z to an integer (base 256 of ord(char)) .>"^X . .^" rotate "^X . .^" ["Plain" -> " . .^^X", "Chocolate" -> ". .^^X ", "Nuts" -> " .^^X . "]  # Python 2.7.6, 99 bytes def c(t):n=hash(t)%3;return" ___\n/"+" ^."[n]+" "+" ."[n]+"\\\n|"+[" ","^ ^"," . "][n]+"|\n\\___/"  This algorithm relies on the fact that hash(cookie)%3 gives 0 when cookie = "Plain", 1 when cookie = "Nut and 2 when cookie = "Chocolate. If anyone knows a way to make this code shorter, please let me know in the comments. • Optional arguments are most certainly allowed Aug 4 '15 at 19:42 • "Use any means to do so." Yes, optional arguments are allowed. Aug 4 '15 at 19:44 • Okay, but I think I'll still stick with the first one and leave the second one as it is. Aug 4 '15 at 19:46 • @BetaDecay I just don't think that optional arguments really are in the spirit of code-golf. I don't really know why, I just think that it shouldn't be allowed. Now that they are both the same length, I removed the optional-arguments version. Aug 4 '15 at 19:58 • @Loovjo Using strange and unusual methods are the whole spirit of code golf :) Aug 4 '15 at 20:01 # C: 122 q(char *p){char *t,*m;int i=*p%3;t=i?i%2?". .":" ":"^ ";m=i?i%2?" . ":" ":"^ ^";printf(" ___\n/%s\\ \n|%s|\n\\___/",t,m);}  Explanation after i finish golfing. Example of use:  int main(void){ q("Plain"); printf("\n"); q("Nut"); printf("\n"); q("Chocolate"); }  • 105 bytes Jul 13 '20 at 2:04 # CJam, 49 48 bytes " ___ /""^ ^ ^. . ."S7*+6/rci=3/"\ |"*"| \___/"  Try it online in the CJam interpreter. ### How it works " ___ /" e# Push that string. "^ ^ ^. . ."S7*+6/ e# Push that string, append 7 spaces and split into chunks of length 6. e# This pushes ["^ ^ ^" ". . . " " "]. rci e# Read from STDIN, cast to character, then to integer. e# "Plain", "Chocolate", "Nuts" -> 'P', 'C', 'N' -> 80, 67, 78 = e# Select the corresponding element from the array. e# Arrays wrap around in CJam, so for an array A of length 3, e# A80= is A2=, A67= is A1= and A78= is A0=. 3/ e# Split into chunks of length 3. "\ |"* e# Join those chunks, using that string as separator. "| \___/" e# Push that string.  At the end, CJam automatically prints all elements on the stack. # Javascript (ES6), 90 s=>" ___\n/"+(s.length-4?s.length-5?". .\\\n| . ":" \\\n| ":"^ \\\n|^ ^")+"|\n\\___/"  This is an anonymous arrow function. It uses the length of the input to determine which cookie to draw. Explanation: s=> " ___\n/" + //build the first part of the cookie (s.length - 4 ? //if the length is 4, this condition will evaluate to 0, which coerces to false. Otherwise it is true s.length - 5 ? //if the length is 5, this evaluates to false; otherwise true ". .\\\n| . " : //build the unique part of the Chocolate cookie, if length was not 5 " \\\n| " //build the unique part of the Plain cookie, if length was 5 : "^ \\\n|^ ^" //build the unique part of the Nuts cookie, if length was 4 ) + "|\n\\___/" //build the last part of the cookie, and implicitly return the built string  To test: f=s=>" ___\n/"+(s.length-4?s.length-5?". .\\\n| . ":" \\\n| ":"^ \\\n|^ ^")+"|\n\\___/" console.log(f("Nuts")) console.log(f("Plain")) console.log(f("Chocolate"))  # BrainFuck, 481447 436 bytes Why not BrainFuck?, the program can probably be golfed more, but I think it's pretty neat. ,>++++++[-<---------->]<-------[----------->>>-<<+<[-->->+<<]]>>>+>>++.<+++++++++[->>>>>>>++++++++++<+++++<++++++++++++++<++++++++++<+++++<++++++++++<+++<]++++++++++>+++.>+++++...>++>++>-->+>++++<<<<<<<.<<<[->>>>>>.>>>.<<<<<.>>>>>.<<.<<<<.>>>>>.<<<<.>>>>>.<<<<<.>>>>.<<<<<.>>>>.<<...>.<<<<<<]>[->>>>>.<<...>>>.<<<<.>>>>>.<<<<...>>>>.<<<<<.>>>>.<<...>.<<<<<]>[->>>>.>>>>.<<<<<<..>>>.<<<<.>>>>>.>>.<<<<<<.>>>>>>.<<.<<<<<.>>>>.<<...>.<<<<]  C# With indentation and line break using System; class Cookie { static void Main() { String E="",N="",C=Console.ReadLine(); if(C=="P"){E=" ";N=" ";} if(C=="C"){E=". .";N=" . ";} if(C=="N"){E="^ ";N="^ ^";} Console.Write(" ___ \n/" + E + "\\ \n|" + N + "|\n\\___/"); } }  Golfed (225 Characters) using System;class X{static void Main(){String E="",N="",C=Console.ReadLine();if(C=="P"){E=" ";N=" ";}if(C=="C"){E=". .";N=" . ";}if(C=="N"){E="^ ";N="^ ^";}Console.Write(" ___ \n/" + E + "\\ \n|" + N + "|\n\\___/");}}[![enter image description here][1]][1]  • Why not String C= Console.ReadLine(),E= ...etc? – rpax Aug 14 '15 at 21:03 • Hey @rpax, Your comment helped me trim 2 characters. Thanks. Aug 14 '15 at 22:47 ## C# 6, 105 bytes So very nearly got this sub-100 bytes, no idea where to squeeze the last few bytes from though :C string C(string t)=>$" ___\n/{(t[0]=='C'?". .\\\n| . ":t[0]=='N'?"^  \\\n|^ ^":"   \\\n|   ")}|\n\\___/";


# Pyth, 58545352 50 bytes

+d*\_3p+\/j"\\
|"c@["^  ^ ^"*". "3*d6)Chz3\|"\___/


I don't think this can be golfed more. I was really trying to squeze this in under 50 bytes

• A quick and easy one is ". . . " -> *". "3 Aug 5 '15 at 6:51
• If your interested, I found a nice method to do this in 42 bytes. Aug 10 '15 at 15:15

## JavaScript (ES6), 72 bytes

About as simple as it gets… new lines are counted as 1 byte each.

f=s=> ___
/${s[4]?s[5]?. .\\ | . : \\ | :^ \\ |^ ^}| \\___/  ### Demo As it is ES6, this demo only works in Firefox and Safari for now. f=s=> ___ /${s[4]?s[5]?. .\\
| . :   \\
|   :^  \\
|^ ^}|
\\___/

// Snippet stuff

A.innerHTML = f("Nuts");
B.innerHTML = f("Plain");
C.innerHTML = f("Chocolate");
<p>Nuts</p>
<pre id=A></pre>

<p>Plain</p>
<pre id=B></pre>

<p>Chocolate</p>
<pre id=C></pre>

# Commodore 64 BASIC, 181 bytes

10 INPUT A$20 IF A$="PLAIN" THEN B$="/ \":C$="|   |"
30 IF A$="CHOCOLATE" THEN B$="/. .\":C$="| . |" 40 IF A$="NUTS" THEN C$="/^ \":C$="|^ ^|"
50 PRINT" ___":PRINT B$:PRINT C$:PRINT"\___/"


Notes:

Instead of backslashes \ the SHIFT-M characters have been used, for slashes / - SHIFT-N and for pipes | - SHIFT-T. SHIFT-Z (card diamond sign) was used for ^. In fact characters do not matter as they all occupy one byte each.

Because on C64 each command (PRINT, INPUT, THEN, etc.) takes 2 bytes in memory (or some even one, IIRC), the BASIC language was worth trying (however, it took more bytes than I expected).

The program size was calculated by measuring free memory before typing the program (38909 bytes) and after (38728 bytes), using PRINT FRE(0)+65536 command, giving 181 bytes of difference.

Code tested and screenshots prepared with this tool: http://codeazur.com.br/stuff/fc64_final/ (GPL).

Screenshots:

# Lua 5.3, 113 Bytes 112 Bytes

c=io.read()print(' ___\n/'..(c=='plain'and'   \\\n|   'or c=='nut'and'^  \\\n|^ ^'or'. .\\\n| . ')..'|\n\\___/')


It uses a lot of the ternary operator and string concatenation, and I squeezed out all whitespace that isn't part of the output itself.

## Java 258 217 characters/bytes

Golfed

class C{public static void main(String[] a){p(" ___");if(a[0].equals("Chocolate")) {p("/. .\\");p("| . |");}if(a[0].equals("Nut")){p("/^  \\");p("|^ ^|");}p("\\___/");}static void p(String s) {System.out.println(s);}}


Original

class C {
public static void main(String[] a) {
p(" ___");
if(a[0].equals("Chocolate")) {
p("/. .\\");
p("| . |");
}
if(a[0].equals("Nut")){
p("/^  \\");
p("|^ ^|");
}
p("\\___/");
}
static void p(String s) {
System.out.println(s);
}
}


# LUA 270 characters 270 bytes

    c = io.read()
if c == "plain" then
print" ___"
print"/   \\"
print"|   |"
print"\\___/"
elseif c == "chocolate" then
print" ___"
print"/. .\\"
print"| . |"
print"\\___/"
elseif c == "nut" then
print" ___"
print"/^  \\"
print"|^ ^|"
print"\\___/"
end

• this is my second answer to any challenges Aug 10 '15 at 22:26
• The "What type of cookie do you want" can be taken out, it isn't needed. That takes out 39 bytes right there. Aug 10 '15 at 22:39
• This is a code-golf challenge. Try to shorten your code a little. E.g. You don't need the initial print, shorten cookie to c, remove whitespace during ifs, remove those unnecessary io.read()s, the first and last line of a cookie is always the same, .... Aug 11 '15 at 10:33
• @BassetHound removed the print statement Aug 11 '15 at 10:43
• @Jakube shortened cookie to c Aug 11 '15 at 10:43

## LOLCODE 265 characters

HAI
I HAS A T
GIMMEH T
VISIBLE " ___"
BOTH SAEM T AN "Chocolate", O RLY?
YA RLY
VISIBLE "/. .\"
VISIBLE "| . |"
OIC
BOTH SAEM T AN "Nut", O RLY?
YA RLY
VISIBLE "/^ ^\"
VISIBLE "|^  |"
OIC
BOTH SAEM T AN "Plain", O RLY?
YA RLY
VISIBLE "/   \"
VISIBLE "|   |"
OIC
VISIBLE "\___/"
KTHXBYE


Run