Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (setf dishes '(
- ("a" (("1" 10) ("2" 20) ("3" 10)))
- ("b" (("2" 5) ("4" 5) ("6" 40)))
- ("c" (("3" 3) ("4" 65)))
- ("d" (("1" 20) ("6" 32)))
- )
- )
- (setf prod '(
- ("2" 100)
- ("6" 100)
- ("3" 100)
- ("4" 100)
- )
- )
- (defun and_list (a)
- (cond
- ((null a) t)
- (t (and (car a) (and_list (cdr a))))
- )
- )
- ; have product (p) in product list (pl) -> t | nil
- (defun have_prod (p pl)
- (cond
- ((null pl) nil)
- ((and (equal (car p) (caar pl)) (< (cadr p) (cadar pl))) t)
- (t (have_prod p (cdr pl)))
- )
- )
- ; can cook dish (d) with product list (p) -> t | nil
- (defun can_cook (d p)
- (and_list (mapcar (lambda (a) (have_prod a p)) (cadr d)))
- )
- ; remove product (p) from product list (pl) -> list(2)
- (defun rm_prod (p pl)
- (cond
- ((null pl) nil)
- ((and (equal (car p) (caar pl)) (< (cadr p) (cadar pl))) (cons (list (car p) (- (cadar pl) (cadr p))) (rm_prod p (cdr pl)))) ; mb without AND (right side)
- (t (cons (car pl) (rm_prod p (cdr pl))))
- )
- )
- ; create menu list -> list(1)
- (defun menu (d p)
- (cond
- ((null d) nil)
- ((null p) nil)
- ((can_cook (car d) p) (cons (caar d) (menu (cdr d) (rm_prod (car d) p))))
- (t (menu (cdr d) p))
- )
- )
- (print (menu dishes prod))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement