Skip to content

Instantly share code, notes, and snippets.

@ClathomasPrime
Created October 4, 2018 14:57
Show Gist options
  • Save ClathomasPrime/cac7431d19e20707dfaf9c35ea6b8fc9 to your computer and use it in GitHub Desktop.
Save ClathomasPrime/cac7431d19e20707dfaf9c35ea6b8fc9 to your computer and use it in GitHub Desktop.
Algo Q6
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