Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.List;
- closest :: [(Float, Float)] -> Float
- closest l = closest' $ sortBy (\a b -> (compare (fst a) (fst b))) l
- where
- closest' [] = 10.0**30.0;
- closest' [a] = 10.0**30.0;
- closest' [a,b] = dist a b
- closest' s =
- let h = splitAt ((length s) `div` 2) s
- d1 = closest' (fst h)
- d2 = closest' (snd h)
- md = min d1 d2
- xp = fst $ head $ (snd h)
- t = sortBy (\a b -> (compare (snd a) (snd b))) [x | x<-s, (abs ((fst x)-xp)) < md]
- d3 = comp6 t
- in (min md d3)
- where
- comp6 [] = 10.0**30.0;
- comp6 (x:xs) = min (comp6' x (take 6 xs)) (comp6 xs)
- where
- comp6' p [] = 10.0**30.0;
- comp6' p (x:xs) = (min (dist p x) (comp6' p xs))
- dist a b = sqrt ( ((fst a) - (fst b))**2.0 + ((snd a) - (snd b))**2.0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement