fork download
  1. upari :: [Int] -> [[(Int, Int)]]
  2. upari [] = []
  3. upari [a, b] = [[(a, b)]]
  4. upari (a:xa) = foldl ff [] [0..length(xa) - 1]
  5. where
  6. ff :: [[(Int, Int)]] -> Int -> [[(Int, Int)]]
  7. ff acc i = acc ++ map (\res -> (a, b):res) (upari(left ++ right))
  8. where
  9. (left, b:right) = splitAt i xa
  10.  
  11.  
  12. main = mapM_ print (upari [1..6])
Success #stdin #stdout 0s 6268KB
stdin
Standard input is empty
stdout
[(1,2),(3,4),(5,6)]
[(1,2),(3,5),(4,6)]
[(1,2),(3,6),(4,5)]
[(1,3),(2,4),(5,6)]
[(1,3),(2,5),(4,6)]
[(1,3),(2,6),(4,5)]
[(1,4),(2,3),(5,6)]
[(1,4),(2,5),(3,6)]
[(1,4),(2,6),(3,5)]
[(1,5),(2,3),(4,6)]
[(1,5),(2,4),(3,6)]
[(1,5),(2,6),(3,4)]
[(1,6),(2,3),(4,5)]
[(1,6),(2,4),(3,5)]
[(1,6),(2,5),(3,4)]