Skip to content

Commit

Permalink
visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Dec 11, 2023
1 parent 3d09104 commit 437703c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion common/src/Advent/Coord.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ right (C y x) = C y (x+1)
invert :: Coord -> Coord
invert (C y x) = C x y

-- | Swap x and y coordinates
-- | Negate and swap x and y coordinates
invert' :: Coord -> Coord
invert' (C y x) = C (-x) (-y)

Expand Down
18 changes: 15 additions & 3 deletions solutions/src/2023/10.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# Language LambdaCase, ImportQualifiedPost, TransformListComp #-}
{-# Language LambdaCase, ImportQualifiedPost, BlockArguments #-}
{-|
Module : Main
Description : Day 10 solution
Expand Down Expand Up @@ -46,13 +46,16 @@ L7JLJL-JLJLJL--JLJ.L
module Main (main) where

import Advent (getInputMap)
import Advent.Coord (cardinal, invert, invert', south, north, west, turnRight, Coord)
import Advent.Coord (cardinal, invert, invert', south, north, west, turnRight, Coord, drawPicture)
import Advent.Search (dfsN, dfsOn)
import Data.List (nub, (\\))
import Control.Monad (when)
import Data.List (nub)
import Data.Map (Map)
import Data.Map qualified as Map
import Data.Maybe (isJust)
import Data.Set (Set)
import Data.Set qualified as Set
import System.Environment (lookupEnv)

-- | Parse the input and print out answers to both parts.
--
Expand All @@ -73,6 +76,15 @@ main =
print (length route `quot` 2)
print (length contained)

visualize <- isJust <$> lookupEnv "VISUALIZE"
when visualize
do putStr (drawPicture (fmap pretty input `Map.restrictKeys` pipe <>
Map.fromSet (const '') (Set.fromList contained)))

pretty :: Char -> Char
pretty = \case
'7' -> ''; 'J' -> ''; 'F' -> ''; 'L' -> ''; '-' -> ''; '|' -> ''; _ -> ' '

pickStart :: Map Coord Char -> (Coord, Coord)
pickStart input = head $
[ (k, dir)
Expand Down

0 comments on commit 437703c

Please sign in to comment.