d15p2
This commit is contained in:
parent
bf84c6c1bb
commit
f686950106
|
@ -1,32 +1,24 @@
|
|||
import Control.Lens
|
||||
import Data.List
|
||||
import Data.List.Split
|
||||
import qualified Data.Map as M
|
||||
import Linear.V2
|
||||
|
||||
type Sensor = (V2 Int, V2 Int)
|
||||
|
||||
type Cave = M.Map (V2 Int) Char
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
input <- map (splitOneOf "=,:") . lines <$> readFile "input"
|
||||
let sensors = map parse input
|
||||
-- print $ "Cave from to: " ++ show (caveMinMaxX sensors)
|
||||
-- print $ part1 (caveMinMaxX sensors) sensors
|
||||
-- print $ getBorder sensors
|
||||
-- print $ last [(x,x) | x<-[0..10000]]
|
||||
-- print $ last [(x,y) | x<-[0..10000], y<-[0..10000], x==y]
|
||||
print "hello world"
|
||||
|
||||
|
||||
allCandidates :: [Sensor] -> [Int] -> [V2 Int]
|
||||
allCandidates (s:ss) ds = undefined
|
||||
print $ "Cave from to: " ++ show (caveMinMaxX sensors)
|
||||
print $ part1 (caveMinMaxX sensors) sensors
|
||||
print $ part2 sensors
|
||||
|
||||
getBorder :: [Sensor] -> [V2 Int]
|
||||
getBorder (s:ss) = map (+ (fst s)) xs ++ getBorder ss
|
||||
where xs = [V2 x (d - x) | x<-[-d..0]++[1..d]]
|
||||
d = succ $ dist s
|
||||
getBorder (s:ss) = map (+ fst s) xs ++ getBorder ss
|
||||
where
|
||||
xs =
|
||||
concat $ take 4 $ iterate (map perp) [V2 x (d - x) | x <- [0 .. pred d]]
|
||||
d = succ $ dist s
|
||||
getBorder [] = []
|
||||
|
||||
caveMinMaxX :: [Sensor] -> (Int, Int)
|
||||
caveMinMaxX sensors = (minimum k, maximum l)
|
||||
|
@ -41,6 +33,16 @@ part1 (a, b) sensors = length $ filter (== '#') $ map (checkPoint sensors) xs
|
|||
where
|
||||
xs = [V2 x 2000000 | x <- [a .. b]] --y=10 for testinput
|
||||
|
||||
part2 :: [Sensor] -> Int
|
||||
part2 sensors =
|
||||
f $
|
||||
head $
|
||||
filter (\x -> checkPoint sensors x == ' ') $
|
||||
filter (\(V2 x y) -> x >= 0 && x <= 4000000 && y >= 0 && y <= 4000000) $
|
||||
getBorder sensors -- <=20 for testinput
|
||||
where
|
||||
f = (+) <$> view _y <*> ((*) 4000000 . view _x)
|
||||
|
||||
parse :: [String] -> Sensor
|
||||
parse [_, a, _, b, _, c, _, d] = (V2 (read a) (read b), V2 (read c) (read d))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user