Last active
October 27, 2019 05:40
-
-
Save hvariant/e155eb7f724cf4e2304eea557eec4f97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rnd_permu :: [a] -> IO [a] | |
| rnd_permu xs = do | |
| arr <- A.newListArray (1,l) xs | |
| forM [1..l] $ \i -> do | |
| j <- randomRIO (1, i) | |
| vi <- (A.readArray arr i) | |
| vj <- (A.readArray arr j) | |
| A.writeArray arr j vi | |
| A.writeArray arr i vj | |
| pure vj | |
| where | |
| l = length xs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rnd_permu :: [a] -> IO [a] | |
| rnd_permu xs = do | |
| arr <- newArray l xs | |
| forM [1..l] $ \i -> do | |
| j <- randomRIO (1, i) | |
| vi <- (A.readArray arr i) | |
| vj <- (A.readArray arr j) | |
| A.writeArray arr j vi | |
| A.writeArray arr i vj | |
| pure vj | |
| where | |
| l = length xs | |
| newArray :: Int -> [a] -> IO (IOArray Int a) | |
| newArray n xs = A.newListArray (1,n) xs |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
error: