golf a bit

This commit is contained in:
Quinten Kock 2022-12-05 16:32:56 +01:00
parent d493d56d28
commit 62742b2c6c
1 changed files with 7 additions and 7 deletions

View File

@ -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