import AoC
-import Data.List
-import Data.Maybe
+-- import Data.List
+-- import Data.Maybe
import Linear (V2(..), (^+^), (^-^))
import qualified Data.Set as S
let galaxies = mkGalaxies text
-- print galaxies
-- print $ expandGalaxies galaxies 10
+
+ -- print $ allDist $ expandGalaxies 2 galaxies
+ -- print $ allDist $ expandGalaxies (10^6) galaxies
+
print $ part1 galaxies
print $ part2 galaxies
part1, part2 :: Galaxies -> Int
part1 = allDistances . expandGalaxies 2
-part2 = allDistances . expandGalaxies (10^6)
+part2 = allDistances . expandGalaxies 10e6
allDistances :: Galaxies -> Int
-allDistances gs = case S.minView gs of
- Nothing -> 0
- Just (g, gs') -> (S.foldl' (addDist g) 0 gs) + allDistances gs'
- where addDist g1 acc g2 = acc + distance g1 g2
+allDistances gs = snd $ S.foldl' addGalaxy (S.empty, 0) gs
+ where addGalaxy (seen, d) new =
+ (S.insert new seen, S.foldl' (addDist new) d seen)
+ addDist g1 d g2 = d + distance g1 g2
distance :: Position -> Position -> Int
distance g1 g2 = abs dr + abs dc