Some things fixed
This commit is contained in:
parent
f89d165c94
commit
4f73ff3c56
15
day10.hs
15
day10.hs
|
@ -1,4 +1,5 @@
|
||||||
import Data.List as List
|
import Data.List as List
|
||||||
|
import Debug.Trace as Trace
|
||||||
|
|
||||||
|
|
||||||
main = do
|
main = do
|
||||||
|
@ -6,13 +7,14 @@ main = do
|
||||||
let layers = lines content
|
let layers = lines content
|
||||||
let indexlayers = map(\x-> mapInd(\x y -> (y,x)) x ) layers
|
let indexlayers = map(\x-> mapInd(\x y -> (y,x)) x ) layers
|
||||||
let points = concat (mapInd(\x y->map(\x->((fst x,y),snd x))x) $ indexlayers)
|
let points = concat (mapInd(\x y->map(\x->((fst x,y),snd x))x) $ indexlayers)
|
||||||
let asteroids = map fst (filter(\(x,y) -> y == '#' ) points)
|
let asteroids = (Trace.traceShowId(map fst (filter(\(x,y) -> y == '#' ) points)))
|
||||||
|
let changedAsteroids = changeCoordinate asteroids (2,2)
|
||||||
--let sortedAsteroids = sortBy sortDistance asteroids
|
--let sortedAsteroids = sortBy sortDistance asteroids
|
||||||
--let view = length (getViews (asteroids) (3,4))
|
--let view = length (getViews (asteroids) (3,4))
|
||||||
--let result = List.maximum(map(\x-> length(getViews (asteroids) x)) (asteroids))
|
--let result = List.maximum(map(\x-> length(getViews (asteroids) x)) (asteroids))
|
||||||
let views = (getViews asteroids (2,2))
|
let views = (getViews asteroids (2,2))
|
||||||
let lines = map reduce(map(\(x,y)-> ((x-2),(y-2))) (getBorder (2,2) 4))
|
let lines = map reduce(map(\(x,y)-> ((x-2),(y-2))) (getBorder (2,2) 4))
|
||||||
let order = destroyOrders asteroids lines (2,2) []
|
let order = destroyOrders changedAsteroids lines (2,2) []
|
||||||
--let destroyed = destroyOrder views lines []
|
--let destroyed = destroyOrder views lines []
|
||||||
--mapM putStrLn (map(\(x,y)->(show x ) ++(show y)) asteroids)
|
--mapM putStrLn (map(\(x,y)->(show x ) ++(show y)) asteroids)
|
||||||
--mapM putStrLn (map(\(x,y)->(show x ) ++(show y)) sortedAsteroids)
|
--mapM putStrLn (map(\(x,y)->(show x ) ++(show y)) sortedAsteroids)
|
||||||
|
@ -25,10 +27,10 @@ main = do
|
||||||
destroyOrders :: [(Int,Int)] ->[(Int,Int)] -> (Int,Int) -> [(Int,Int)] -> [(Int,Int)]
|
destroyOrders :: [(Int,Int)] ->[(Int,Int)] -> (Int,Int) -> [(Int,Int)] -> [(Int,Int)]
|
||||||
destroyOrders ast laser station out
|
destroyOrders ast laser station out
|
||||||
|length ast > 0 = do
|
|length ast > 0 = do
|
||||||
let views = getViews ast station
|
let views = foldl getView [] ast
|
||||||
let destroyed = destroyOrder views laser []
|
let destroyed = (Trace.traceShowId(destroyOrder views laser []))
|
||||||
let newout = out ++ destroyed
|
let newout = out ++ destroyed
|
||||||
let newast = ast \\ destroyed
|
let newast = (Trace.traceShowId(ast \\ destroyed))
|
||||||
destroyOrders newast laser station newout
|
destroyOrders newast laser station newout
|
||||||
|otherwise = out
|
|otherwise = out
|
||||||
|
|
||||||
|
@ -43,6 +45,9 @@ sortDistance ((a,b),c) ((a2,b2),c2)
|
||||||
getViews :: [(Int,Int)] -> (Int,Int) -> [(Int,Int)]
|
getViews :: [(Int,Int)] -> (Int,Int) -> [(Int,Int)]
|
||||||
getViews xs (a,b) = foldl getView [](delete (0,0)( (map(\(x,y) -> ((x-a),(y-b)))xs)))
|
getViews xs (a,b) = foldl getView [](delete (0,0)( (map(\(x,y) -> ((x-a),(y-b)))xs)))
|
||||||
|
|
||||||
|
changeCoordinate :: [(Int, Int)] -> (Int,Int) -> [(Int,Int)]
|
||||||
|
changeCoordinate xs (a,b) = (delete (0,0)( (map(\(x,y) -> ((x-a),(y-b)))xs)))
|
||||||
|
|
||||||
getView :: [(Int,Int)] -> (Int,Int) -> [(Int,Int)]
|
getView :: [(Int,Int)] -> (Int,Int) -> [(Int,Int)]
|
||||||
getView xs y
|
getView xs y
|
||||||
|notElem (reduce y) (map reduce xs) = xs ++ [y]
|
|notElem (reduce y) (map reduce xs) = xs ++ [y]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user