From 62742b2c6cc8452162518a3067de6ca78578659d Mon Sep 17 00:00:00 2001 From: Quinten Kock Date: Mon, 5 Dec 2022 16:32:56 +0100 Subject: [PATCH] golf a bit --- 2022/day05.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/2022/day05.hs b/2022/day05.hs index 88d3bea..d15908a 100644 --- a/2022/day05.hs +++ b/2022/day05.hs @@ -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