day 9 part 2

This commit is contained in:
Gattix 2022-12-10 05:59:41 +01:00
parent ad899280f1
commit 8d23ac258a

@ -1,7 +1,5 @@
import Linear.V2
import Data.List
import Data.List.Split
import Control.Lens
type Rope = (V2 Int,V2 Int)
@ -39,15 +37,3 @@ tailMove (V2 a b) = V2 (f a) (f b)
| abs a == abs b = if abs a == 2 then x `div` 2 else 0
| abs a + abs b == 1 = 0
| otherwise = if abs x == 2 then x `div` 2 else x
p :: Int -> [Int] -> String
p n (x:xs) = if n == x then '#' : p (n+1) xs else '.' : p (n+1) (x:xs)
p _ [] = []
print2D :: Int -> [V2 Int] -> [String]
print2D n coords
| n == (pred minY) = []
| otherwise = p minX line : print2D (n-1) coords
where line = sort $ map (^._x) (filter (\(V2 _ a) -> a == n) coords)
minY = minimum $ map (^._y) coords
minX = minimum $ map (^._x) coords