-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path400.hs
More file actions
25 lines (20 loc) · 688 Bytes
/
Copy path400.hs
File metadata and controls
25 lines (20 loc) · 688 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import Control.Applicative
import Control.Monad.State
import Data.List
takeList n xs =
take (length xs `div` n)
$ evalState (mapM (State . splitAt) $ repeat n) xs
byPairs [] = []
byPairs (x:y:xs) = (x,y):byPairs xs
reverseEven :: [[a]] -> [[a]]
reverseEven xs = fst $ runState (mapM t xs) False
where t xs = do
x <- get
modify not
return $ if x then reverse xs else xs
solve :: String -> [a] -> [a]
solve x = concat . transpose . reverseEven . takeList (read x)
main = do
ls <- byPairs . takeWhile (/= "0") . lines <$> getContents
mapM_ (putStrLn . uncurry solve) ls
return ()