i love it when rows are vertical and columns are horizontal
This commit is contained in:
parent
018bae2654
commit
84eaa42c9a
17
Day13_1.hs
17
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
|
||||
| otherwise = ' '
|
||||
in putStrLn $ insert (width+1) '\n' $ map display field
|
Loading…
Reference in New Issue