Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (setq reciepts `(
- `(soup (water 1.2) (potato 0.3) (meat 0.4) (tomato 0.2))
- `(salad (tomato 1) (cucumber 1) (oil 0.1))
- `(garnish (water 1) (meat 1) (oil 0.3) (potato 0.5) (tomato 0.3))
- ))
- (setq store `((water 2) (potato 5) (tomato 3) (oil 2) (cucumber 5) (meat 2)))
- (defun GetBorsh(order)
- (CheckInStore)
- (setq recieptName (CheckReciept order))
- (setq components (cdr(cadr recieptName)))
- (setq i 0)
- (dolist (itemStore store)
- (dolist (component components)
- (cond ((eq (car itemStore) (car component))
- (cond ((>= (cadr itemStore) (cadr component))
- (setq newValue (- (cadr itemStore) (cadr component) ))
- (setf (cdr(elt store i)) (cons newValue `()) )
- ))
- )
- )
- )
- (setf i (+ i 1))
- )
- )
- (defun CheckInStore()
- (format t "~%We try to cook ~s" (car(cadr recieptName)))
- (dolist (itemStore store)
- (dolist (component components)
- (cond ((eq (car itemStore) (car component))
- (cond ((>= (cadr itemStore) (cadr component))
- (format t "~% ~s found. Need ~s, have ~s" (car itemStore) (cadr component) (cadr itemStore) ))
- (t (error "~% not enought resources ~s. Need ~s, have ~s" (car itemStore) (cadr component) (cadr itemStore) )))
- )
- )
- )
- )
- (format t "~%All done. Take you order" )
- )
- (defun CheckReciept(reciept)
- (dolist(item reciepts)
- (setq currentReciept (car(cadr item)))
- (cond ((eq currentReciept (car reciept))
- (return-from checkReciept item)
- )
- )
- )
- (error "Wrong reciept name")
- )
- (GetBorsh `(salad))
- (format t "~% Remain in store ~s" store )
- (GetBorsh `(garnish))
- (format t "~% Remain in store ~s" store )
- (GetBorsh `(soup))
- (format t "~% Remain in store ~s" store )
- We try to cook SALAD
- TOMATO found. Need 1, have 3
- OIL found. Need 0.1, have 2
- CUCUMBER found. Need 1, have 5
- All done. Take you order
- Remain in store ((WATER 2) (POTATO 5) (TOMATO 2) (OIL 1.9) (CUCUMBER 4) (MEAT 2))
- We try to cook GARNISH
- WATER found. Need 1, have 2
- POTATO found. Need 0.5, have 5
- TOMATO found. Need 0.3, have 2
- OIL found. Need 0.3, have 1.9
- MEAT found. Need 1, have 2
- All done. Take you order
- Remain in store ((WATER 1) (POTATO 4.5) (TOMATO 1.7) (OIL 1.5999999) (CUCUMBER 4) (MEAT 1))
- We try to cook SOUP
- *** - not enought resources WATER. Need 1.2, have 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement