i love it when rows are vertical and columns are horizontal

This commit is contained in:
Agatha Lovelace 2021-12-13 19:44:23 +02:00
parent 018bae2654
commit 84eaa42c9a
1 changed files with 9 additions and 8 deletions

View File

@ -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