Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #53265 > unrolled thread
| Started by | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| First post | 2016-12-10 21:36 +0000 |
| Last post | 2016-12-10 14:21 -0800 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.forth
Maximizing "Robert L." <No_spamming@noWhere_7073.org> - 2016-12-10 21:36 +0000
Re: Maximizing jean-pierre@buechi-schmitt.ch - 2016-12-10 14:21 -0800
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Date | 2016-12-10 21:36 +0000 |
| Subject | Maximizing |
| Message-ID | <o2hshf$1ach$1@gioia.aioe.org> |
> 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))
A parenthesis is missing.
>
> ; 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))
Ruby:
def f x,y; 9*x+4*y-x*x-y*y; end
a=(0..9).to_a
a.product(a).max_by{|x| f *x}
===>
[4, 2]
In Forth?
--
Today Dr. Duke quoted an article from Breitbart on an agreement between the EU
and internet companies like Facebook, YouTube, and Twitter to effectively
censor "hate speech," which of course is anything Jews hate to hear.
http://www.renseradioarchives.com/dduke/
[toc] | [next] | [standalone]
| From | jean-pierre@buechi-schmitt.ch |
|---|---|
| Date | 2016-12-10 14:21 -0800 |
| Message-ID | <41209e19-acd0-4aa6-819f-5edc41c26b2e@googlegroups.com> |
| In reply to | #53265 |
Le samedi 10 décembre 2016 22:36:53 UTC+1, Robert L. a écrit :
> > 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))
>
> A parenthesis is missing.
>
> >
> > ; 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))
>
> Ruby:
>
> def f x,y; 9*x+4*y-x*x-y*y; end
>
> a=(0..9).to_a
> a.product(a).max_by{|x| f *x}
> ===>
> [4, 2]
>
> In Forth?
Good evening
What's the question ?
cordially
Hans-Peter
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web