Advertisement
bogatyr285

Check product in store

Dec 9th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.57 KB | None | 0 0
  1. (setq reciepts `(
  2.         `(soup (water 1.2) (potato 0.3) (meat 0.4) (tomato 0.2))
  3.         `(salad  (tomato 1) (cucumber 1) (oil 0.1))
  4.         `(garnish (water 1) (meat 1) (oil 0.3) (potato 0.5) (tomato 0.3))
  5.     ))
  6. (setq store `((water 2) (potato 5) (tomato 3) (oil 2) (cucumber 5) (meat 2)))
  7. (defun GetBorsh(order)
  8.     (CheckInStore)
  9.     (setq recieptName (CheckReciept order))    
  10.     (setq components (cdr(cadr recieptName)))
  11.     (setq i 0)
  12.     (dolist (itemStore store)
  13.        (dolist (component components)
  14.             (cond ((eq (car itemStore) (car component))
  15.                    (cond ((>= (cadr itemStore) (cadr component))
  16.                    (setq newValue (- (cadr itemStore) (cadr component) ))
  17.                            (setf (cdr(elt store i))  (cons newValue `()) )  
  18.                    ))
  19.                 )
  20.             )
  21.         )
  22.         (setf i (+ i 1))
  23.     )
  24. )
  25. (defun CheckInStore()
  26. (format t "~%We try to cook ~s" (car(cadr recieptName)))
  27.  (dolist (itemStore store)
  28.         (dolist (component components)
  29.                (cond ((eq (car itemStore) (car component))
  30.                    (cond ((>= (cadr itemStore) (cadr component))
  31.                         (format t "~% ~s found. Need ~s, have ~s" (car itemStore) (cadr component) (cadr itemStore) ))
  32.                    (t (error  "~% not enought resources ~s. Need ~s, have ~s" (car itemStore) (cadr component) (cadr itemStore) )))
  33.                )
  34.             )
  35.         )
  36.     )
  37.   (format t "~%All done. Take you order" )  
  38. )
  39. (defun CheckReciept(reciept)
  40.     (dolist(item reciepts)
  41.         (setq currentReciept  (car(cadr item)))
  42.         (cond ((eq currentReciept (car reciept))
  43.                   (return-from checkReciept  item)
  44.                )
  45.         )
  46.     )
  47.     (error "Wrong reciept name")
  48. )
  49. (GetBorsh `(salad))
  50. (format t "~% Remain in store ~s" store )
  51. (GetBorsh `(garnish))
  52. (format t "~% Remain in store ~s" store )
  53. (GetBorsh `(soup))
  54. (format t "~% Remain in store ~s" store )
  55.  
  56.  
  57. We try to cook SALAD
  58.   TOMATO found. Need 1, have 3
  59.   OIL found. Need 0.1, have 2
  60.   CUCUMBER found. Need 1, have 5
  61.   All done. Take you order
  62. Remain in store ((WATER 2) (POTATO 5) (TOMATO 2) (OIL 1.9) (CUCUMBER 4) (MEAT 2))
  63.  
  64. We try to cook GARNISH
  65.   WATER found. Need 1, have 2
  66.   POTATO found. Need 0.5, have 5
  67.   TOMATO found. Need 0.3, have 2
  68.   OIL found. Need 0.3, have 1.9
  69.   MEAT found. Need 1, have 2
  70. All done. Take you order
  71. Remain in store ((WATER 1) (POTATO 4.5) (TOMATO 1.7) (OIL 1.5999999) (CUCUMBER 4) (MEAT 1))
  72.  
  73. We try to cook SOUP
  74. *** - not enought resources WATER. Need 1.2, have 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement