d15p2
This commit is contained in:
parent
bf84c6c1bb
commit
f686950106
|
@ -1,32 +1,24 @@
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Data.List
|
|
||||||
import Data.List.Split
|
import Data.List.Split
|
||||||
import qualified Data.Map as M
|
|
||||||
import Linear.V2
|
import Linear.V2
|
||||||
|
|
||||||
type Sensor = (V2 Int, V2 Int)
|
type Sensor = (V2 Int, V2 Int)
|
||||||
|
|
||||||
type Cave = M.Map (V2 Int) Char
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
input <- map (splitOneOf "=,:") . lines <$> readFile "input"
|
input <- map (splitOneOf "=,:") . lines <$> readFile "input"
|
||||||
let sensors = map parse input
|
let sensors = map parse input
|
||||||
-- print $ "Cave from to: " ++ show (caveMinMaxX sensors)
|
print $ "Cave from to: " ++ show (caveMinMaxX sensors)
|
||||||
-- print $ part1 (caveMinMaxX sensors) sensors
|
print $ part1 (caveMinMaxX sensors) sensors
|
||||||
-- print $ getBorder sensors
|
print $ part2 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
|
|
||||||
|
|
||||||
getBorder :: [Sensor] -> [V2 Int]
|
getBorder :: [Sensor] -> [V2 Int]
|
||||||
getBorder (s:ss) = map (+ (fst s)) xs ++ getBorder ss
|
getBorder (s:ss) = map (+ fst s) xs ++ getBorder ss
|
||||||
where xs = [V2 x (d - x) | x<-[-d..0]++[1..d]]
|
where
|
||||||
d = succ $ dist s
|
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 :: [Sensor] -> (Int, Int)
|
||||||
caveMinMaxX sensors = (minimum k, maximum l)
|
caveMinMaxX sensors = (minimum k, maximum l)
|
||||||
|
@ -41,6 +33,16 @@ part1 (a, b) sensors = length $ filter (== '#') $ map (checkPoint sensors) xs
|
||||||
where
|
where
|
||||||
xs = [V2 x 2000000 | x <- [a .. b]] --y=10 for testinput
|
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 :: [String] -> Sensor
|
||||||
parse [_, a, _, b, _, c, _, d] = (V2 (read a) (read b), V2 (read c) (read d))
|
parse [_, a, _, b, _, c, _, d] = (V2 (read a) (read b), V2 (read c) (read d))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user