Skip to content

Commit de505d4

Browse files
committed
Day 25: Make it a visualization :)
Use `runghc` so it is slow enough to be pretty (`ghc -O3` will make it go way too fast)
1 parent a34d0f0 commit de505d4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

2021/25/Main.hs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import qualified Data.Array as A
2+
import Debug.Trace
23

34
parse = (\(y,x,l) -> A.array ((0, 0), (y, x)) l)
45
. (\l -> (maximum $ map (fst . fst) l, maximum $ map (snd . fst) l, l))
@@ -7,11 +8,11 @@ parse = (\(y,x,l) -> A.array ((0, 0), (y, x)) l)
78
. map (zip [0..])
89
. lines
910

10-
steps m = loop m
11+
steps m = loop $ trace ("\27[2J" ++ toStr (0,0) m) m
1112
where
1213
(my,mx) = snd $ A.bounds m
1314
loop m | m == m' = 1
14-
| m /= m' = 1 + loop m'
15+
| m /= m' = 1 + (loop $ trace ("\27[2J" ++ toStr (0,0) m') m')
1516
where
1617
n = m A.// stepEW (0, 0)
1718
m' = n A.// stepNS (0, 0)
@@ -29,5 +30,9 @@ steps m = loop m
2930
| otherwise = ns
3031
where d = (succ y `mod` succ my, x)
3132
ns = stepNS (y, x + 1)
33+
toStr p@(y, x) m
34+
| y > my = "\n"
35+
| x > mx = '\n' : toStr (y + 1, 0) m
36+
| otherwise = m A.! p : toStr (y, x + 1) m
3237

3338
main = parse <$> readFile "input.txt" >>= print . steps

0 commit comments

Comments
 (0)