diff --git a/codesnippets.hs b/codesnippets.hs new file mode 100644 index 0000000..121f5d1 --- /dev/null +++ b/codesnippets.hs @@ -0,0 +1,21 @@ +module Snippets where + +import Control.Lens +import Data.List +import Linear.V2 + +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 = nub $ sort $ map (^. _x) (filter (\(V2 _ a) -> a == n) coords) + minY = minimum $ map (^. _y) coords + minX = minimum $ map (^. _x) coords