Frank Buss <fb@frank-buss.de> writes:
Looks like you are searching for a functional way of doing this. In Haskell you could write it like this (I'm a Haskell newbie, I'm sure this can be written better, but at least it works)
f (x,y) = 9*x + 4*y - x*x - y*y
best = foldr1 max values
where values = [(f(x,y), (x,y)) | x<-[0..9], y<-[0..9]]
max t1 t2 = if (fst t1) >= (fst t2) then t1 else t2
let f x y = 9*x+4*y-x*x-y*y in
foldl1' max [(f x y,(x,y)) | x <- [0..9], y<-[0..9]]
is a little simpler. Uses the max built-in and foldl1' which operates
left to right and is strict.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 403 |
Nodes: | 16 (2 / 14) |
Uptime: | 44:12:50 |
Calls: | 8,407 |
Calls today: | 2 |
Files: | 13,171 |
Messages: | 5,905,028 |