golf a bit
This commit is contained in:
parent
d493d56d28
commit
62742b2c6c
|
|
@ -2,7 +2,7 @@ import Data.List (transpose, delete)
|
|||
import Data.List.Split (chunksOf, splitOn)
|
||||
import Data.Char (isSpace)
|
||||
|
||||
data Command = Move {amount :: Int, from :: Int, to :: Int} deriving Show
|
||||
data Command = Move Int Int Int
|
||||
|
||||
type State = [[Char]]
|
||||
|
||||
|
|
@ -18,14 +18,14 @@ listApp 0 f (x:xs) = f x : xs
|
|||
listApp n f (x:xs) = x : listApp (n-1) f xs
|
||||
|
||||
moveN :: Command -> State -> State
|
||||
moveN (Move 0 from to) = id
|
||||
moveN (Move n from to) = moveN (Move (n-1) from to) . move (Move 1 from to)
|
||||
moveN (Move 0 _ _) = id
|
||||
moveN (Move n f t) = moveN (Move (n-1) f t) . move (Move 1 f t)
|
||||
|
||||
move :: Command -> State -> State
|
||||
move (Move amount from to) state = addTo $ popFrom state where
|
||||
popFrom = listApp from (drop amount)
|
||||
elems = take amount (state !! from)
|
||||
addTo = listApp to (elems ++ )
|
||||
move (Move n f t) state = addTo $ popFrom state where
|
||||
popFrom = listApp f (drop n)
|
||||
elems = take n (state !! f)
|
||||
addTo = listApp t (elems ++ )
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
|
|
|
|||
Loading…
Reference in New Issue