{ lib, utils, ... }: with lib; with builtins; with utils; let grid = map stringToCharacters (readLines ./input); antenna_map = genAttrs (unique (filter (invert (eq ".")) (flatten grid))) (c: filter (i: matIndex i grid == c) (getMatrixIndices grid)); inGrid = (flip inRangeMatrix) grid; makeAntiNodesPairwise = x: y: [ (vecSum x (vecDiff x y)) (vecSum y (vecDiff y x)) ]; makeAntiNodesRay = x: y: let direction = (shortenVec (vecDiff x y)); in (raycastUntil (invert inGrid) direction x) ++ (raycastUntil (invert inGrid) (scalarVecMul (-1) direction) y); makeAntiNodes = nodeFunc: coords: concatLists (map (a: concatLists (map (nodeFunc a) (remove a coords)) ) coords); in rec { # inherit antenna_map; part1 = map (makeAntiNodes makeAntiNodesPairwise) (attrValues antenna_map) |> concatLists |> filter inGrid |> unique |> length; part2 = map (makeAntiNodes makeAntiNodesRay) (attrValues antenna_map) |> concatLists |> unique |> length; # pairwiseTest = makeAntiNodesPairwise [0 0] [2 2]; # shortVecTest = shortenVec [2 6]; # x = [1 1]; # y = [1 2]; # rayTest = makeAntiNodesRay x y; # direction = (shortenVec (vecDiff x y)); }