X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-19.git;a=blobdiff_plain;f=advent24%2Fsrc%2Fadvent24b.hs;fp=advent24%2Fsrc%2Fadvent24b.hs;h=a259df4ce30ca0f52de6290604bfbac385f86b9f;hp=1b173b78e55fe18c661ca73f415f932d7d3f23c2;hb=6a1a537ac8f0d4fab44b806aa8986dce4aab8f9e;hpb=38d570c8528a68170cbfaf50cc750c7d4e1cde5c diff --git a/advent24/src/advent24b.hs b/advent24/src/advent24b.hs index 1b173b7..a259df4 100644 --- a/advent24/src/advent24b.hs +++ b/advent24/src/advent24b.hs @@ -1,4 +1,4 @@ -import Debug.Trace +-- import Debug.Trace import qualified Data.Set as S @@ -14,7 +14,7 @@ gridSize = 5 main :: IO () main = do grid0 <- readGrid - print grid0 + -- print grid0 let finalGrid = head $ drop 200 $ iterate update grid0 print $ S.size finalGrid @@ -36,27 +36,39 @@ neighbourSpaces cell = neighbourSpacesLeft :: Cell -> Grid neighbourSpacesLeft (Cell {..}) - | column == 4 && row == 3 = S.fromList [ Cell { level = (level + 1), row = r, column = 5} | r <- [1..gridSize] ] - | column == 1 = S.singleton ( Cell { level = (level - 1), row = 3, column = 2}) - | otherwise = S.singleton ( Cell { level, row, column = (column - 1)}) + | column == 4 && row == 3 = S.fromList [ Cell { level = (level + 1), + row = r, column = 5} + | r <- [1..gridSize] ] + | column == 1 = S.singleton ( Cell { level = (level - 1), + row = 3, column = 2}) + | otherwise = S.singleton ( Cell { column = (column - 1), ..}) neighbourSpacesRight :: Cell -> Grid neighbourSpacesRight (Cell {..}) - | column == 2 && row == 3 = S.fromList [ Cell { level = (level + 1), row = r, column = 1} | r <- [1..gridSize] ] - | column == 5 = S.singleton ( Cell { level = (level - 1), row = 3, column = 4}) - | otherwise = S.singleton ( Cell { level, row, column = (column + 1)}) + | column == 2 && row == 3 = S.fromList [ Cell { level = (level + 1), + row = r, column = 1} + | r <- [1..gridSize] ] + | column == 5 = S.singleton ( Cell { level = (level - 1), + row = 3, column = 4}) + | otherwise = S.singleton ( Cell { column = (column + 1), ..}) neighbourSpacesAbove :: Cell -> Grid neighbourSpacesAbove (Cell {..}) - | row == 4 && column == 3 = S.fromList [ Cell { level = (level + 1), row = 5, column = c} | c <- [1..gridSize] ] - | row == 1 = S.singleton ( Cell { level = (level - 1), row = 2, column = 3}) - | otherwise = S.singleton ( Cell { level, row = (row - 1), column}) + | row == 4 && column == 3 = S.fromList [ Cell { level = (level + 1), + row = 5, column = c} + | c <- [1..gridSize] ] + | row == 1 = S.singleton ( Cell { level = (level - 1), + row = 2, column = 3}) + | otherwise = S.singleton ( Cell { row = (row - 1), ..}) neighbourSpacesBelow :: Cell -> Grid neighbourSpacesBelow (Cell {..}) - | row == 2 && column == 3 = S.fromList [ Cell { level = (level + 1), row = 1, column = c} | c <- [1..gridSize] ] - | row == 5 = S.singleton ( Cell { level = (level - 1), row = 4, column = 3}) - | otherwise = S.singleton ( Cell { level, row = (row + 1), column}) + | row == 2 && column == 3 = S.fromList [ Cell { level = (level + 1), + row = 1, column = c} + | c <- [1..gridSize] ] + | row == 5 = S.singleton ( Cell { level = (level - 1), + row = 4, column = 3}) + | otherwise = S.singleton ( Cell { row = (row + 1), ..}) countOccupiedNeighbours :: Cell -> Grid -> Int