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.List.Split (chunksOf, splitOn)
|
||||||
import Data.Char (isSpace)
|
import Data.Char (isSpace)
|
||||||
|
|
||||||
data Command = Move {amount :: Int, from :: Int, to :: Int} deriving Show
|
data Command = Move Int Int Int
|
||||||
|
|
||||||
type State = [[Char]]
|
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
|
listApp n f (x:xs) = x : listApp (n-1) f xs
|
||||||
|
|
||||||
moveN :: Command -> State -> State
|
moveN :: Command -> State -> State
|
||||||
moveN (Move 0 from to) = id
|
moveN (Move 0 _ _) = id
|
||||||
moveN (Move n from to) = moveN (Move (n-1) from to) . move (Move 1 from to)
|
moveN (Move n f t) = moveN (Move (n-1) f t) . move (Move 1 f t)
|
||||||
|
|
||||||
move :: Command -> State -> State
|
move :: Command -> State -> State
|
||||||
move (Move amount from to) state = addTo $ popFrom state where
|
move (Move n f t) state = addTo $ popFrom state where
|
||||||
popFrom = listApp from (drop amount)
|
popFrom = listApp f (drop n)
|
||||||
elems = take amount (state !! from)
|
elems = take n (state !! f)
|
||||||
addTo = listApp to (elems ++ )
|
addTo = listApp t (elems ++ )
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue