Created
October 4, 2018 14:57
-
-
Save ClathomasPrime/cac7431d19e20707dfaf9c35ea6b8fc9 to your computer and use it in GitHub Desktop.
Algo Q6
This file contains 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
module Q6 where | |
import Control.Monad | |
import Control.Monad.Random | |
import Data.Numbers.Primes | |
import Data.List | |
import Data.Function | |
thing :: MonadRandom m => Int -> m [Int] | |
thing n = thing' n | |
where | |
thing' 0 = return [] | |
thing' k = do | |
rs <- getRandomRs (1,n) | |
let pairs = zip [1..k] rs | |
collisions = filter ((>= 2) . length) | |
. groupBy ((==) `on` snd) | |
. sortBy (compare `on` snd) | |
$ pairs | |
(k :) <$> thing' (length collisions) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment