September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,16 +1,23 @@
|
|||
import Data.List
|
||||
import System.Random
|
||||
import Control.Monad
|
||||
import Control.Arrow
|
||||
import Data.Ord
|
||||
import Data.List (minimumBy, tails, unfoldr, foldl1') --'
|
||||
|
||||
vecLeng [[a,b],[p,q]] = sqrt $ (a-p)^2+(b-q)^2
|
||||
import System.Random (newStdGen, randomRs)
|
||||
|
||||
findClosestPair = foldl1' ((minimumBy (comparing vecLeng). ). (. return). (:)) .
|
||||
concatMap (\(x:xs) -> map ((x:).return) xs) . init . tails
|
||||
import Control.Arrow ((&&&))
|
||||
|
||||
import Data.Ord (comparing)
|
||||
|
||||
vecLeng [[a, b], [p, q]] = sqrt $ (a - p) ^ 2 + (b - q) ^ 2
|
||||
|
||||
findClosestPair =
|
||||
foldl1'' ((minimumBy (comparing vecLeng) .) . (. return) . (:)) .
|
||||
concatMap (\(x:xs) -> map ((x :) . return) xs) . init . tails
|
||||
|
||||
testCP = do
|
||||
g <- newStdGen
|
||||
let pts :: [[Double]]
|
||||
pts = take 1000. unfoldr (Just. splitAt 2) $ randomRs(-1,1) g
|
||||
print . (id &&& vecLeng ) . findClosestPair $ pts
|
||||
g <- newStdGen
|
||||
let pts :: [[Double]]
|
||||
pts = take 1000 . unfoldr (Just . splitAt 2) $ randomRs (-1, 1) g
|
||||
print . (id &&& vecLeng) . findClosestPair $ pts
|
||||
|
||||
main = testCP
|
||||
|
||||
foldl1'' = foldl1'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue