Please don’t rely on this Gitea instance being around forever. If any of your build scripts use my (kageru’s) projects hosted here, check my Github or IEW on Github for encoding projects. If you can’t find what you’re looking for there, tell me to migrate it.

Some things fixed

master
ArranunW 3 years ago
parent f89d165c94
commit 4f73ff3c56

@ -1,4 +1,5 @@
import Data.List as List
import Debug.Trace as Trace
main = do
@ -6,13 +7,14 @@ main = do
let layers = lines content
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 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 view = length (getViews (asteroids) (3,4))
--let result = List.maximum(map(\x-> length(getViews (asteroids) x)) (asteroids))
let views = (getViews asteroids (2,2))
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 []
--mapM putStrLn (map(\(x,y)->(show x ) ++(show y)) asteroids)
--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 ast laser station out
|length ast > 0 = do
let views = getViews ast station
let destroyed = destroyOrder views laser []
let views = foldl getView [] ast
let destroyed = (Trace.traceShowId(destroyOrder views laser []))
let newout = out ++ destroyed
let newast = ast \\ destroyed
let newast = (Trace.traceShowId(ast \\ destroyed))
destroyOrders newast laser station newout
|otherwise = out
@ -43,6 +45,9 @@ sortDistance ((a,b),c) ((a2,b2),c2)
getViews :: [(Int,Int)] -> (Int,Int) -> [(Int,Int)]
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 xs y
|notElem (reduce y) (map reduce xs) = xs ++ [y]

Loading…
Cancel
Save