diff options
author | Andreas Grois <andi@grois.info> | 2022-12-22 09:02:30 +0100 |
---|---|---|
committer | Andreas Grois <andi@grois.info> | 2022-12-22 09:02:30 +0100 |
commit | 158e1420311db30021110aa9368b97bdf7a11a7c (patch) | |
tree | 6fc2c7cc419a21790680918ab7fd8f590282dcfc | |
parent | 3f06a81930ee1281de670a7c7e8776c1c32e2d2a (diff) |
Slight improvement to Day8 part 1
-rw-r--r-- | Day8/app/Main.hs | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/Day8/app/Main.hs b/Day8/app/Main.hs index 3945c76..34f9c16 100644 --- a/Day8/app/Main.hs +++ b/Day8/app/Main.hs @@ -62,15 +62,23 @@ getVisibleTrees s = getVisibleTreesFromSide firstSide $ getVisibleTreesFromSide thirdSide $ getVisibleTreesFromSide fourthSide Set.empty where firstSide = s - secondSide = rotateForest firstSide - thirdSide = rotateForest secondSide - fourthSide = rotateForest thirdSide - -rotateForest :: ForestWithIds -> ForestWithIds -rotateForest (ForestWithIds l) = ForestWithIds $ rotateRectangularList l - where rotateRectangularList [l] = reverse $ map return l - rotateRectangularList (l:ls) = addColumnL (reverse l) (rotateRectangularList ls) - addColumnL (i:is) (l:ls) = (i:l):addColumnL is ls + secondSide = rotateForestLeft firstSide + thirdSide = rotateForestLeft secondSide + fourthSide = rotateForestLeft thirdSide + +rotateForestLeft :: ForestWithIds -> ForestWithIds +rotateForestLeft (ForestWithIds l) = ForestWithIds $ rotateRectangularListLeft l + +rotateRectangularListLeft :: [[a]] -> [[a]] +rotateRectangularListLeft = reverse . transposeRectangularList + +rotateRectangularListRight :: [[a]] -> [[a]] +rotateRectangularListRight = transposeRectangularList . reverse + +transposeRectangularList :: [[a]] -> [[a]] +transposeRectangularList [l] = map return l +transposeRectangularList (l:ls) = addColumnL l (transposeRectangularList ls) + where addColumnL (i:is) (l:ls) = (i:l):addColumnL is ls addColumnL [] [] = [] getVisibleTreesFromSide :: ForestWithIds -> Set.Set TreeId -> Set.Set TreeId @@ -93,4 +101,8 @@ newtype ForestWithIds = ForestWithIds [[TreeWithId]] solveDay8Part2 :: Day8Input -> Int -solveDay8Part2 x = undefined
\ No newline at end of file +solveDay8Part2 x = 0 + +-- Well, part 2 sucks. But we can do a scanl to transform each tree in each of the 4 sides to its viewing distance. +-- Or, probably it's easier to just write the function instead of using scanl. +-- And once that's döner, we can rotate everything back to the original orientation, multiply up and boom, partay!
\ No newline at end of file |