Add nicer formatting to day03
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -8,15 +8,27 @@ main = do
|
|||||||
let input = parseInput inputText
|
let input = parseInput inputText
|
||||||
putStr "Part 1: "
|
putStr "Part 1: "
|
||||||
putStrLn $ part1 input
|
putStrLn $ part1 input
|
||||||
--putStrLn $ show $ growBoard (-5, -6) $ growBoard (5, 6) emptyBoard
|
putStrLn $ show $ applyAt (-4, 4) emptyBoard
|
||||||
|
|
||||||
part1 :: ([Dir], [Dir]) -> String
|
part1 :: (Wires, Wires) -> String
|
||||||
part1 _ = " "
|
part1 _ = " "
|
||||||
|
|
||||||
parseInput :: String -> ([Dir], [Dir])
|
parseInput :: String -> (Wires, Wires)
|
||||||
parseInput input = (wires1, wires2)
|
parseInput input = (wires1, wires2)
|
||||||
where
|
where
|
||||||
wires1:wires2:_ = input |> lines |> map (splitOn "," .> map parseDir)
|
wires1:wires2:_ = input |> lines |> fmap (splitOn "," .> fmap parseDir)
|
||||||
|
|
||||||
|
applyAtPos :: Board -> Board
|
||||||
|
applyAtPos board = applyAt (pos board) board
|
||||||
|
|
||||||
|
applyAt :: (Int, Int) -> Board -> Board
|
||||||
|
applyAt (x, y) board =
|
||||||
|
board |> growBoard (x * 2, y * 2) |> mapBoardMat (updateMat (x, y))
|
||||||
|
|
||||||
|
--applyWires :: Wires -> Board -> Board
|
||||||
|
--applyWires wires board =
|
||||||
|
--applyWire :: Dir -> Board -> Board
|
||||||
|
type Wires = [Dir]
|
||||||
|
|
||||||
type Mat = [[Bool]]
|
type Mat = [[Bool]]
|
||||||
|
|
||||||
@@ -30,9 +42,6 @@ data Board =
|
|||||||
emptyBoard :: Board
|
emptyBoard :: Board
|
||||||
emptyBoard = Board {mat = [], pos = (0, 0), origin = (0, 0)}
|
emptyBoard = Board {mat = [], pos = (0, 0), origin = (0, 0)}
|
||||||
|
|
||||||
ensureBoardPos :: (Int, Int) -> Board -> Board
|
|
||||||
ensureBoardPos _ board = board
|
|
||||||
|
|
||||||
growBoard :: (Int, Int) -> Board -> Board
|
growBoard :: (Int, Int) -> Board -> Board
|
||||||
growBoard (x, y) board = growBoardX x (growBoardY y board)
|
growBoard (x, y) board = growBoardX x (growBoardY y board)
|
||||||
|
|
||||||
@@ -131,6 +140,14 @@ dirPair (Dn n) = (0, n)
|
|||||||
dirPair (Lt n) = (-n, 0)
|
dirPair (Lt n) = (-n, 0)
|
||||||
dirPair (Rt n) = (n, 0)
|
dirPair (Rt n) = (n, 0)
|
||||||
|
|
||||||
|
updateMat :: (Int, Int) -> Mat -> Mat
|
||||||
|
updateMat (x, y) mat = newMat
|
||||||
|
where
|
||||||
|
(rowHead, _:rowTail) = splitAt y mat
|
||||||
|
row = mat !! y
|
||||||
|
(colHead, _:colTail) = splitAt x row
|
||||||
|
newMat = rowHead ++ [colHead ++ True : colTail] ++ rowTail
|
||||||
|
|
||||||
growMatDir :: Dir -> Mat -> Mat
|
growMatDir :: Dir -> Mat -> Mat
|
||||||
growMatDir dir mat
|
growMatDir dir mat
|
||||||
| dirMag dir == 0 = mat
|
| dirMag dir == 0 = mat
|
||||||
@@ -160,7 +177,7 @@ matW :: Mat -> Int
|
|||||||
matW mat =
|
matW mat =
|
||||||
if matH mat == 0
|
if matH mat == 0
|
||||||
then 0
|
then 0
|
||||||
else mx (map length mat)
|
else mx (fmap length mat)
|
||||||
|
|
||||||
matH :: Mat -> Int
|
matH :: Mat -> Int
|
||||||
matH mat = length mat
|
matH mat = length mat
|
||||||
|
|||||||
Reference in New Issue
Block a user