diff --git a/Day13_1.hs b/Day13_1.hs index de3dd93..44ce728 100644 --- a/Day13_1.hs +++ b/Day13_1.hs @@ -3,7 +3,7 @@ import System.IO (openFile) import Data.Text (unpack, splitOn, pack) import Prelude hiding (splitAt) import Data.Char (digitToInt) -import Data.List (nub) +import Data.List (nub, transpose) splitAt :: String -> String -> [String] splitAt delimiter str = map unpack $ splitOn (pack delimiter) $ pack str @@ -34,14 +34,15 @@ main = do let coords = (\[a,b] -> (read a, read b) :: (Int, Int)) <$> map (splitAt ",") coords' folds = map (last . splitAt " ") folds' - let result = nub $ foldl (\acc x -> map (fold x) acc) coords folds + let result = map (\(a,b) -> (b,a)) + $ nub + $ foldl (\acc x -> map (fold x) acc) coords folds - let width = maximum $ fst <$> result - height = maximum $ snd <$> result - field = (,) <$> [0..width] <*> [0..height] + let width = maximum $ snd <$> result + height = maximum $ fst <$> result + field = (,) <$> [0..height] <*> [0..width] let display x | x `elem` result = '#' - | otherwise = '.' - -- the text is actually vertical, because of course it is - in putStrLn $ insert (height+1) '\n' $ map display field \ No newline at end of file + | otherwise = ' ' + in putStrLn $ insert (width+1) '\n' $ map display field \ No newline at end of file