Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 27 |
Nodes: | 6 (0 / 6) |
Uptime: | 38:58:01 |
Calls: | 631 |
Calls today: | 2 |
Files: | 1,187 |
D/L today: |
23 files (29,781K bytes) |
Messages: | 174,061 |
I'm looping over two variables to maximize a function, returning x and
y that maximize f. Any way to do it without the setf in the body?
; Here's a function you can paste to the REPL.
(defun f (x y)
(- (+ (* 9 x) (* 4 y))
(* x x)
(* y y))
; And here's what I'm trying to do:
(let ((best-x -1)
(best-y -1)
(max nil))
(loop :for x :below 10 :do
(loop :for y :below 10 :do
(let ((n (f x
y)))
(if (or (null max) (> n
max))
(setf best-x
x
best-y
y
max n)))))
(values best-x best-y))