4
\$\begingroup\$

Challenge

Your program will take in a string from stdin, and output multiple lines to stdout.

An example of input looks like this:

My favorite Chipotle order:

B1113YNNY

Let's break it down:

  • The first character is either A (burrito), or B (burrito bowl).
  • The second character is 1 (black beans), or 2 (pinto beans).
  • The third character is either 1 (white rice), or 2 (brown rice).
  • The fourth character is either 1 (chicken), 2 (sofritas), or 3 (steak).
  • The fifth character is either 1 (mild salsa), 2 (medium salsa), or 3 (hot salsa).
  • The last four characters are Y if they want the item, or N otherwise:
  • character 6 is corn
  • character 7 is guacamole
  • character 8 is sour cream
  • character 9 is cheese

A working program for this challenge will output this to stdout:

burrito bowl with:
black beans
white rice
chicken
hot salsa
corn
cheese

Replace the above words with the words acquired from input.

Clarifications.

Standard loopholes are disallowed.
You may only get input from stdin, and only put output to stdout.

\$\endgroup\$
4
  • 3
    \$\begingroup\$ We have some Defaults for I/O here. Also functions instead of full programs are always allowed. Overriding those should only be done if there is a specific reason for that, which I don't see here. \$\endgroup\$
    – Denker
    Aug 23, 2016 at 6:38
  • 4
    \$\begingroup\$ May be worth removing and submitting to the sandbox to get it up to scratch? \$\endgroup\$ Aug 23, 2016 at 7:01
  • \$\begingroup\$ @JonathanAllan sure \$\endgroup\$ Aug 23, 2016 at 14:04
  • \$\begingroup\$ It amazes me that all answers have zero votes so far! \$\endgroup\$ Oct 25, 2016 at 3:40

9 Answers 9

1
\$\begingroup\$

Python 3, 293 bytes

j=input();a,b,c,d,e,f,g,h,i=[1-ord(c)%7%5for c in j];print('\n'.join(('burrito'+[' bowl',''][a]+' with:',['pinto','black'][b]+' beans',['brown','white'][c]+' rice',['sofritas','chicken','steak'][d],['medium','mild','hot'][e]+' salsa'))+'\ncorn'*f+'\nguacamole'*g+'\nsour cream'*h+'\ncheese'*i)

Mostly basic lookups with a little modulo trickery for the indexes of items:
AB123YN yielding indexes -1,-2,1,0,-1,1,0 respectively, and
using string multiplication for the optional items rather than a lookup.

\$\endgroup\$
1
\$\begingroup\$

Python 2, 302 298 bytes

o=input()
print"\n".join([s[0]+s[1+(ord(c)+1)%3]+s[-1]for(x,c)in zip(["burrito ,,bowl, with:",",black,pinto, beans",",white,brown, rice",",chicken,sofritas,chicken,",",mild,medium,hot, salsa"],o)for s in[x.split(",")]]+[x for(x,c)in zip(["corn","guacamole","sour cream","cheese"],o[5:])if c=="Y"])

EDIT: according to the consensus on meta, I'm allowed to use input instead of raw_input, requiring the user of the program to type his or her Chipotle order in quotes! Thanks, @StevenH. for informing me of this.

\$\endgroup\$
0
\$\begingroup\$

Python 2, 336 335 Bytes

q,i=input(),int
print"burrito "+{"A":"","B":"bowl"}[q[0]]+" with:\n"+["black","pinto"][i(q[1])-1]+" beans\n"+["white","brown"][i(q[2])-1]+" rice\n"+["chicken","sofritas","steak"][i(q[3])-1]+"\n"+["mild","medium","hot"][i(q[4])-1]+" salsa\n"+"\n".join([x for y,x in enumerate(["corn","guacamole","sour cream","cheese"]) if q[y+5]=="Y"])

Try it online!

Removed one byte by renaming int: i=int

\$\endgroup\$
5
  • \$\begingroup\$ You can save some bytes by interleaving the strings like "wbhriotwen"[i(q[2])-1::2], also for black and pinto \$\endgroup\$
    – Karl Napf
    Oct 23, 2016 at 13:31
  • \$\begingroup\$ Don't you mean raw_input? \$\endgroup\$
    – Omar
    Nov 25, 2016 at 1:39
  • \$\begingroup\$ @Omar, requiring input to be wrapped in quotation marks and escaped as would be needed for using input() over raw_input() is allowed by meta consensus. This is especially true when the original question specifies that input is passed as a string, as it is here. \$\endgroup\$
    – Steven H.
    Nov 25, 2016 at 2:49
  • \$\begingroup\$ Ooh, excellent, @StevenH., I'll change that in my submission, then. :) \$\endgroup\$
    – Omar
    Nov 25, 2016 at 2:56
  • \$\begingroup\$ No problem! Glad I could help. \$\endgroup\$
    – Steven H.
    Nov 25, 2016 at 3:00
0
\$\begingroup\$

Pyth, 225 Bytes

=rQ0s["burrito "?xGhQ"bowl "k"with:")+@,"pinto""black"shtQ" beans"+@,"brown""white"shttQ" rice"@c"steak chicken sofritas")s@Q3+@c"hot medium mild")s@Q4" salsa"seMf}\y@QhT[,5"corn\n",6"guacamole\n",7"sour cream\n",8"cheese\n")
\$\endgroup\$
0
\$\begingroup\$

Batch, 445 364 bytes

@echo off
set/ps=
set l=call:l 
%l%"burrito with:" "burrito bowl with:"
%l%"black beans" "pinto beans" 
%l%"white rice" "brown rice" 
%l%chicken sofritas steak
%l%"mild salsa" "medium salsa" "hot salsa" 
%l%corn
%l%guacamole
%l%"sour cream"
%l%cheese
exit/b
:l
for %%a in (B N 2 3 3)do if %s:~0,1%==%%a shift
if not "%~1"=="" echo %~1%
set s=%s:~1%

New rewrite saved me 81 bytes. Reading from STDIN conveniently saves a byte over using the command line. Each character of the input is processed in turn to select from a list of options; the characters B, N and 2 cause the second option to be chosen, while 3 causes the third option to be chosen.

\$\endgroup\$
0
\$\begingroup\$

Racket 544 bytes

(let*((s(read-line))(l(string->list s))(lr list-ref)(d displayln)(p display)(c -1)(g(λ()(set! c(+ 1 c))(lr l c))))
(match(g)[#\A(d"burrito with:")][#\B(d"burrito bowl with:")])(match(g)[#\1(d"black beans")][#\2(d"pinto beans")])
(match(g)[#\1(d"white rice")][#\2(d"brown rice")])(match(g)[#\1(d"chicken")][#\2(d"sofritas")][#\3(d"steak")])
(match(g)[#\1(p"mild ")][#\2(p"medium ")][#\3(p"hot ")])(d"salsa")(match(g)[#\Y(d"corn")][#\N""])  
(match(g)[#\Y(d"guacamole")][#\N""])(match(g)[#\Y(d"sour cream")][#\N""])(match(g)[#\Y(d"cheese")][#\N""]))

Ungolfed:

(define (f)
  (let* ((s (read-line))
         (l (string->list s))
         (lr list-ref)
         (d displayln)
         (p display)
         (c -1)
         (g (lambda() (set! c (add1 c)) (lr l c))))
    (match (g)
      [#\A (d "burrito with:")]
      [#\B (d "burrito bowl with:")])
    (match (g)
      [#\1 (d "black beans")]
      [#\2 (d "pinto beans")])
    (match (g)
      [#\1 (d "white rice")]
      [#\2 (d "brown rice")])
    (match (g)
      [#\1 (d "chicken")]
      [#\2 (d "sofritas")]
      [#\3 (d "steak")])
    (match (g)
      [#\1 (p "mild ")]
      [#\2 (p "medium ")]
      [#\3 (p "hot ")])
    (d "salsa")
    (match (g)
      [#\Y (d "corn")]
      [#\N ""])
    (match (g)
      [#\Y (d "guacamole")]
      [#\N ""])
    (match (g)
      [#\Y (d "sour cream")]
      [#\N ""])
    (match (g)
      [#\Y (d "cheese")]
      [#\N ""])))

Testing:

(f)

burrito bowl with:
black beans
white rice
chicken
hotsalsa
corn
cheese
\$\endgroup\$
0
\$\begingroup\$

PHP, 301 Bytes

<?="burrito".($i=$_GET[a])[0]>A?" bowl":""," with:\n".[black,pinto][$i[1]>1]." beans\n".[white,brown][$i[2]>1]." rice\n".[_,chicken,sofritas,steak][$i[3]]."\n".[_,mild,medium,hot][$i[4]]." salsa".["","\ncorn"][$i[5]>N].["","\nguacamole"][$i[6]>N].["","\nsour cream"][$i[7]>N].["","\ncheese"][$i[8]>N];

Previous version 311 Bytes

<?printf("burrito%s with:\n%s beans\n%s rice\n%s\n%s salsa%s%s%s%s",($i=$_GET[a])[0]>A?" bowl":"",[black,pinto][$i[1]>1],[white,brown][$i[2]>1],[_,chicken,sofritas,steak][$i[3]],[_,mild,medium,hot][$i[4]],["","\ncorn"][$i[5]>N],["","\nguacamole"][$i[6]>N],["","\nsour cream"][$i[7]>N],["","\ncheese"][$i[8]>N]);
\$\endgroup\$
0
\$\begingroup\$

C#, 737 Bytes

Not going to win any prizes here...

Golfed:

string O(string s){var c=new List<string>();var m=new Dictionary<int,List<string>>(){{0,new List<string>(){"burrito","burrito bowl"}},{1,new List<string>(){"","black beans","pinto beans"}},{2,new List<string>(){"","white rice","brown rice"}},{3,new List<string>(){"","chicken","sofritas","steak"}},{4,new List<string>(){"","mild salsa","medium salsa","hot salsa"}},{5,new List<string>(){"corn"}},{6,new List<string>(){"guacamole"}},{7,new List<string>(){"sour cream"}},{8,new List<string>(){"cheese"}},};for(int i=0;i<s.Length;i++){if(i==0){c.Add(s[0]=='A'?m[0][0]:m[0][1]+" with:");continue;}if(i>4){c.Add(s[i]=='Y'?m[i][0]:"");continue;}c.Add(m[i][int.Parse(s[i]+"")]);}return string.Join("\n",c.Where(o =>!string.IsNullOrEmpty(o)));}}

Ungolfed:

public string O(string s)
{
  var c = new List<string>();

  var m = new Dictionary<int, List<string>>()
  {
    {0, new List<string>(){"burrito", "burrito bowl"}},
    {1, new List<string>(){"", "black beans", "pinto beans"}},
    {2, new List<string>(){ "", "white rice", "brown rice"}},
    {3, new List<string>(){ "", "chicken", "sofritas", "steak"}},
    {4, new List<string>(){ "", "mild salsa", "medium salsa", "hot salsa"}},
    {5, new List<string>(){"corn"}},
    {6, new List<string>(){"guacamole"}},
    {7, new List<string>(){"sour cream"}},
    {8, new List<string>(){"cheese"}},
  };

  for (int i = 0; i < s.Length; i++)
  {
    if (i == 0)
    {
      c.Add(s[0] == 'A' ? m[0][0] : m[0][1] + " with:");
      continue;
    }

    if (i > 4)
    {
      c.Add(s[i] == 'Y' ? m[i][0] : "");
      continue;
    }

    c.Add(m[i][int.Parse(s[i]+"")]);
  }

  return string.Join("\n", c.Where(o => !string.IsNullOrEmpty(o)));
}

Testing:

  var chipotleOrder = new ChipotleOrder();
  Console.WriteLine(chipotleOrder.P(Console.ReadLine()));
  Console.ReadLine();

Output:

burrito bowl with:
black beans
white rice
chicken
hot salsa
corn
cheese
\$\endgroup\$
0
\$\begingroup\$

JavaScript (ES6), 267

a=>[...a].map((c,i,a,s=x=>`
`+(','+x).split`,`[c])=>i--?i--?i--?i--?i?c>'N'?(c=i,s`corn,guacamole,sour cream,cheese`):'':s`mild,medium,hot`+' salsa':s`chicken,sofritas,steak`:s`white,brown`+' rice':s`black,pinto`+' beans':'burrito'+(c>'A'?' bowl':'')+' with:').join``

Less golfed

a=>
[...a].map((c,i,a,s=x=>'\n'+(','+x).split`,`[c])=>
       i--?i--?i--?i--?i?
       c>'N'?(c=i,s`corn,guacamole,sour cream,cheese`):''
       :s`mild,medium,hot`+' salsa'
       :s`chicken,sofritas,steak`
       :s`white,brown`+' rice'
       :s`black,pinto`+' beans'
       :'burrito'+(c>'A'?' bowl':'')+' with:'
).join``

Test

f=
a=>[...a].map((c,i,a,s=x=>`
`+(','+x).split`,`[c])=>i--?i--?i--?i--?i?c>'N'?(c=i,s`corn,guacamole,sour cream,cheese`):'':s`mild,medium,hot`+' salsa':s`chicken,sofritas,steak`:s`white,brown`+' rice':s`black,pinto`+' beans':'burrito'+(c>'A'?' bowl':'')+' with:').join``  

function update()
{
  O.textContent=f(I.value);
}

update()
<input id=I value="B1113YNNY" oninput='update()'><pre id=O></pre>

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.