new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
16
Task/Closest-pair-problem/Haskell/closest-pair-problem-1.hs
Normal file
16
Task/Closest-pair-problem/Haskell/closest-pair-problem-1.hs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import Data.List
|
||||
import System.Random
|
||||
import Control.Monad
|
||||
import Control.Arrow
|
||||
import Data.Ord
|
||||
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue