diff --git a/Day10/puzzle1.hs b/Day10/puzzle1.hs index a965a2c..32f857a 100644 --- a/Day10/puzzle1.hs +++ b/Day10/puzzle1.hs @@ -1,4 +1,3 @@ -import Data.List (sort) import Data.Char (digitToInt) import Data.List.Split (chunksOf) import Data.Graph (graphFromEdges, path, vertices) @@ -6,7 +5,7 @@ import Data.Graph (graphFromEdges, path, vertices) type Coords = (Int, Int) type V = (String, Int) -getValue :: [[V]] -> (Int, Int) -> V +getValue :: [[V]] -> Coords -> V getValue grid (i, j) = grid !! i !! j getEdges :: [[V]] -> Coords -> [Int] @@ -21,7 +20,7 @@ listVertices grid = let l = length $ head grid main = do contents <- lines <$> readFile "day10.txt" let grid = listVertices contents - edgeCoords = sort [ (x, y) | x <- [0..length grid -1], y <- [0..length (head grid) - 1] ] + edgeCoords = [ (x, y) | x <- [0..length grid -1], y <- [0..length (head grid) - 1] ] edgeList = [ (x, y, z) | ((x, y), z) <- zip (concat grid) (map (getEdges grid) edgeCoords) ] (graph, nodeFromVertex, _) = graphFromEdges edgeList startList = [ x | (_, x, _) <- filter (\(x, _, _) -> x == "0") $ map nodeFromVertex $ vertices graph ] diff --git a/Day12/puzzle1.hs b/Day12/puzzle1.hs index aa722df..92c4557 100644 --- a/Day12/puzzle1.hs +++ b/Day12/puzzle1.hs @@ -5,7 +5,7 @@ import Data.Foldable (toList) type Coords = (Int, Int) type V = (String, Int) -getValue :: [[V]] -> (Int, Int) -> V +getValue :: [[V]] -> Coords -> V getValue grid (i, j) = grid !! i !! j getEdges :: [[V]] -> Coords -> [Int] @@ -17,7 +17,7 @@ listVertices :: [String] -> [[V]] listVertices grid = let l = length $ head grid in chunksOf l $ zip (map (:[]) (concat grid)) [0..] -calculatePerimeter :: (Int -> (String, Int, [Int])) -> Tree Vertex -> Int +calculatePerimeter :: (Vertex -> (String, Vertex, [Vertex])) -> Tree Vertex -> Int calculatePerimeter nodeFromVertex p = let edges = concat [ x | (_, _, x) <- toList $ fmap nodeFromVertex p ] area = 4 * length p in area - length edges