Compare commits
No commits in common. "414cb602af04f756ff2d582ef7494501a9a453b8" and "aedbb3434ea281076dcbb409405b49ce9b113cac" have entirely different histories.
414cb602af
...
aedbb3434e
|
|
@ -1,41 +0,0 @@
|
||||||
module Day13 where
|
|
||||||
import Data.List.Split (splitOn)
|
|
||||||
import Data.List (nub, sort)
|
|
||||||
import qualified Data.HashSet as S
|
|
||||||
import Debug.Trace (trace)
|
|
||||||
|
|
||||||
type Dot = (Int,Int)
|
|
||||||
data Fold = Vertical Int | Horizontal Int deriving Show
|
|
||||||
|
|
||||||
parse :: String -> Dot
|
|
||||||
parse s = (read x, read y) where [x,y] = splitOn "," s
|
|
||||||
|
|
||||||
parseFold :: String -> Fold
|
|
||||||
parseFold s = if axis == "x" then Horizontal (read line) else Vertical (read line) where [axis,line] = splitOn "=" $ last (words s)
|
|
||||||
|
|
||||||
fold :: Fold -> Dot -> Dot
|
|
||||||
fold fold@(Vertical f) (x,y) = (x, if y > f then f - (y-f) else y)
|
|
||||||
fold fold@(Horizontal f) (x,y) = (if x > f then f - (x-f) else x, y)
|
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = do
|
|
||||||
input <- lines <$> getContents
|
|
||||||
let [dots',folds'] = splitOn [""] input
|
|
||||||
let dots = map parse dots'
|
|
||||||
let folds = map parseFold folds'
|
|
||||||
|
|
||||||
putStr "part 1: "
|
|
||||||
let dots1 = S.fromList $ map (fold (head folds)) dots
|
|
||||||
print $ S.size dots1
|
|
||||||
|
|
||||||
putStrLn "part 2: "
|
|
||||||
let dots2 = map (\d -> foldl (flip fold) d folds) dots
|
|
||||||
let dots2' = S.fromList dots2
|
|
||||||
let min_x = minimum $ map fst dots2
|
|
||||||
let max_x = maximum $ map fst dots2
|
|
||||||
let min_y = minimum $ map snd dots2
|
|
||||||
let max_y = maximum $ map snd dots2
|
|
||||||
mapM_ (\y -> do
|
|
||||||
mapM_ (\x -> putChar (if (x,y) `S.member` dots2' then '#' else '.')) [0..max_x]
|
|
||||||
putStrLn ""
|
|
||||||
) [0..max_y]
|
|
||||||
Loading…
Reference in New Issue