May 18 2004
Scheme takeaway
It’s 11 PM, I’m going to be up most of the night, and I haven’t had dinner yet.
I wrote a Scheme program to place the order for our office.
(define order
`((veg-rolls 160)
(veg-rolls 160)
(spring-pancake-roll 140)
(crabmeat-sweet-corn-soup 180)
(special-fried-rice 380)
(chicken-lemon 450)
(chick-hot-sauce 440)))
(printf "Cost: ~a~n~n"
(apply + (map cadr order)))
(printf "Items: ~n~a~n"
(apply string-append
(map (lambda (s)
(format "~a~n" s))
(map symbol->string
(map car order)))))
|
My office mates were… disturbed.
I just realized that my symbol->string is redundant with the use of format for building strings. Ah well. It was a quick hackjob.
One Response to “Scheme takeaway”
Last year when I was doing Andy King’s Prolog course, one of the assignments was to write a Prolog program that’d order Chinese takeaway based on a set of constraints (”Peter likes prawns, but doesn’t want the same as David”, and so on). My housemate Ben similarly wrote an IRC bot for managing takeaway orders: it’d keep track of peoples’ usual orders and let them specify what they wanted this time, then present the entire list to the person placing the order.
This suggests that automated takeaway ordering is an important CS research area. Is anyone offering a PhD in it?