From 8a8721bb2633fc62aa94cc14542157c474cb05f9 Mon Sep 17 00:00:00 2001 From: Gattix Date: Sun, 12 Dec 2021 01:55:00 +0100 Subject: [PATCH] hindent --- 2021/day05/day05.hs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/2021/day05/day05.hs b/2021/day05/day05.hs index 1c4190e..e83613f 100644 --- a/2021/day05/day05.hs +++ b/2021/day05/day05.hs @@ -1,28 +1,31 @@ -import qualified Data.Map as M -import Data.List.Split import Control.Arrow import Control.Monad +import Data.List.Split +import qualified Data.Map as M main :: IO () main = do - input <- map (map read . filter (/="->")) <$> map (splitOneOf ", ") <$> lines <$> readFile "input" + input <- + map (map read . filter (/= "->")) <$> map (splitOneOf ", ") <$> lines <$> + readFile "input" let process = length . M.filter (> 1) . M.fromListWith (+) . toMap - print $ join (***) process $ (filterOrth input,input) + print $ join (***) process $ (filterOrth input, input) filterOrth :: [[Int]] -> [[Int]] filterOrth [] = [] -filterOrth ([x1,y1,x2,y2]:ss) - | x1==x2 || y1==y2 = [x1,y1,x2,y2]:filterOrth ss +filterOrth ([x1, y1, x2, y2]:ss) + | x1 == x2 || y1 == y2 = [x1, y1, x2, y2] : filterOrth ss | otherwise = filterOrth ss -toMap :: [[Int]] -> [((Int,Int),Int)] +toMap :: [[Int]] -> [((Int, Int), Int)] toMap [] = [] -toMap ([x1,y1,x2,y2]:xs) - | y1==y2 = zip ySame (repeat 1) ++ toMap xs - | x1==x2 = zip xSame (repeat 1) ++ toMap xs +toMap ([x1, y1, x2, y2]:xs) + | y1 == y2 = zip ySame (repeat 1) ++ toMap xs + | x1 == x2 = zip xSame (repeat 1) ++ toMap xs | otherwise = zip diag (repeat 1) ++ toMap xs - where diag = zip xRange yRange - ySame = zip xRange (repeat y1) - xSame = zip (repeat x1) yRange - xRange = [x1,x1-(signum $ x1-x2)..x2] - yRange = [y1,y1-(signum $ y1-y2)..y2] + where + diag = zip xRange yRange + ySame = zip xRange (repeat y1) + xSame = zip (repeat x1) yRange + xRange = [x1,x1 - (signum $ x1 - x2) .. x2] + yRange = [y1,y1 - (signum $ y1 - y2) .. y2]