• + 0 comments
    indexed :: [a] -> [(Int,a)]
    indexed xs = go 0 xs
        where go i (a:as) = (i,a) : go (i+1) as
              go _ _ = []
    
    solve :: (Ord a) => [(Int,a)] -> [a]
    solve x =
        let evenList = foldr (\(i,v) acc -> if (even i) then v:acc else acc) [] x
            oddList = foldr (\(i,v) acc -> if (odd i) then v:acc else acc ) [] x
        in concat [ [a,b] | (a,b) <- (flip zip evenList oddList) ]
        
    main = interact $ unlines . map solve . map indexed . tail . words