Skip to content

Instantly share code, notes, and snippets.

@chron
Created August 23, 2013 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chron/6315218 to your computer and use it in GitHub Desktop.
Save chron/6315218 to your computer and use it in GitHub Desktop.
Trying to cut down the size of Jan Dvorak's answer to this golf.se question: http://codegolf.stackexchange.com/questions/12356/manage-a-pie-shop
h=Hash.new 0
loop{$><<'> '
a,b,c=gets.split
puts({list:->{h.map{|x|?|+" %%%ds |"%h.flatten.map{|e|e.to_s.size}.max*2%x}},count:->{h[b]!=0?h[b]:"There is no #{b} pie!"},buy:->{h[c]+=b.to_i},sell:->{h[c]-=b.to_i},exit:->{abort"The pie store has closed!"}}[a.intern][])rescue puts"That's not a valid command."}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment