Generalise allUnorderedPairs
Now that it's in the prelude, the desire to remove diagonals is less obvious than it was.
This commit is contained in:
parent
c608e21e26
commit
e85429629f
@ -108,5 +108,5 @@ listIndex n =
|
||||
[] -> Nothing
|
||||
x : xs -> if n == 0 then Just x else listIndex (n - 1) xs
|
||||
|
||||
allUnorderedPairs :: [a] -> [(a, a)]
|
||||
allUnorderedPairs = concat . join (zipWith (flip $ map . (,)) . tail . tails)
|
||||
allUnorderedPairs :: Bool -> [a] -> [(a, a)]
|
||||
allUnorderedPairs diagonals = concat . join (zipWith (flip $ map . (,)) . (bool tail toList diagonals) . tails)
|
||||
|
||||
@ -40,4 +40,4 @@ puzzle =
|
||||
connectBoxes :: [V3 Int] -> [((V3 Int, V3 Int), DS.DisjointSet (V3 Int))]
|
||||
connectBoxes boxes = zip allPairs $ scanl (flip $ uncurry DS.union) (foldMap DS.singleton boxes) allPairs
|
||||
where
|
||||
allPairs = sortOn (quadrance . uncurry (-)) $ allUnorderedPairs boxes
|
||||
allPairs = sortOn (quadrance . uncurry (-)) $ allUnorderedPairs False boxes
|
||||
|
||||
@ -15,7 +15,7 @@ puzzle =
|
||||
. fmap ((\(V2 x y) -> x * y) . (+ 1) . fmap abs . uncurry (-))
|
||||
. fromMaybe (error "empty input")
|
||||
. nonEmpty
|
||||
. allUnorderedPairs
|
||||
. allUnorderedPairs False
|
||||
]
|
||||
, extraTests = mempty
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user