fork(1) download
  1. import Control.Monad
  2. import System.Random
  3. import Data.List
  4.  
  5. a = [0,1,2,3,3,1,1,2,0,0]
  6. b = [a, a, a, a]
  7.  
  8. f 3 _ = randomRIO (0,3)
  9. f _ 3 = randomRIO (0,3)
  10. f x y = return $ div (x+y) 2
  11.  
  12. z :: [Integer] -> [Integer] -> IO [Integer]
  13. z x y = zipWithM f x y
  14.  
  15. c = filter (\x -> length x == 2) . subsequences
  16.  
  17. r = sequence . map (\x -> z (x!!0) (x!!1)) . c
  18.  
  19. y = foldr (<=<) return . replicate 2
  20.  
  21. main = y r b >>= mapM_ print
  22.  
Success #stdin #stdout 0s 4836KB
stdin
Standard input is empty
stdout
[0,1,2,0,0,1,1,2,0,0]
[0,1,2,0,0,1,1,2,0,0]
[0,1,2,1,1,1,1,2,0,0]
[0,1,2,0,0,1,1,2,0,0]
[0,1,2,1,0,1,1,2,0,0]
[0,1,2,3,0,1,1,2,0,0]
[0,1,2,0,3,1,1,2,0,0]
[0,1,2,0,2,1,1,2,0,0]
[0,1,2,1,2,1,1,2,0,0]
[0,1,2,0,3,1,1,2,0,0]
[0,1,2,0,0,1,1,2,0,0]
[0,1,2,1,0,1,1,2,0,0]
[0,1,2,1,0,1,1,2,0,0]
[0,1,2,1,0,1,1,2,0,0]
[0,1,2,0,3,1,1,2,0,0]