From 46a6c20cdefd7d97ef50090c045c5fb662e7d7e2 Mon Sep 17 00:00:00 2001 From: thornAvery Date: Mon, 13 Dec 2021 10:08:26 +0000 Subject: [PATCH] cleanup --- code/src/13/Main.hs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/code/src/13/Main.hs b/code/src/13/Main.hs index ee55dfa..f824bad 100644 --- a/code/src/13/Main.hs +++ b/code/src/13/Main.hs @@ -20,7 +20,7 @@ solveA :: [(Int,Int)] -> Fold -> Int solveA dots f = length $ nub $ map (crease f) dots solveB :: [(Int,Int)] -> [Fold] -> [String] -solveB dots fs = showPaper $ foldl (\d f -> map (crease f) d) dots fs +solveB dots folds = showPaper $ (foldl (\d f -> map (crease f) d)) dots folds crease :: Fold -> (Int,Int) -> (Int,Int) crease (Hori h) (x,y) = @@ -33,23 +33,21 @@ crease (Vert v) (x,y) = else (x, (v-(y-v))) parseFolds :: [String] -> [Fold] -parseFolds ss = map f ss +parseFolds = map f where g (d:'=':t) = (if d == 'y' then Vert else Hori) (read t) - f s = g (drop 11 s) + f = g . (drop 11) parseDots :: [String] -> [(Int,Int)] -parseDots ss = map f ss +parseDots = map f where g (x:y:_) = ((read x), (read y)) f s = g $ words $ map (\c -> if c == ',' then ' ' else c) s showPaper :: [(Int,Int)] -> [String] -showPaper db = mkPap +showPaper db = map (\y -> mkRow y) [0..mH] where mW = maximum $ map fst $ db mH = maximum $ map snd $ db - f c = if c then '#' else ' ' + f c = if c then '▉' else ' ' mkRow y = [ f $ (x,y) `elem` db | x <- [0..mW] ] - mkPap = map (\y -> mkRow y) [0..mH] -