-
Notifications
You must be signed in to change notification settings - Fork 1
/
scratch.lisp
30 lines (27 loc) · 1008 Bytes
/
scratch.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(defpackage :scratch (:use :cl :iterate))
(in-package :scratch)
(defun score (ingredients)
(reduce #'*
(list
(reduce #'+
(mapcar #'* ingredients (list 5 -1 0 -1)))
(reduce #'+
(mapcar #'* ingredients (list -1 3 -1 0)))
(reduce #'+
(mapcar #'* ingredients (list 0 0 4 0)))
(reduce #'+
(mapcar #'* ingredients (list 0 0 0 2))))))
(defun solve-a (&aux (iterations 0))
(values
(iter outer
(for frosting from 0 to 100)
(iter (for candy from frosting to (- 100 frosting))
(iter (for butterscotch from candy to (- 100 frosting candy))
(for sugar = (- 100 frosting candy butterscotch))
(in outer
(incf iterations)
(maximizing (score (list frosting candy butterscotch sugar)))))))
iterations))
(solve-a)
#; Scratch
(ql:quickload "iterate")