tvl-depot/users/sterni/exercises/aoc/2022/15/15.bqn
sterni c3be4f6f59 feat(sterni/aoc/2022): day15 BQN solution
Part 2 is pretty slow, since we just reuse our fast solution for part 1.
This means we have to check 4000000 which could be reduced a bit by
using a loop. It is tolerably slow, so whatever. (Overall this problem
would have been more fun if the space to check was smaller.)

Change-Id: I1203330fe0364894cfe0318376e583868937b5bd
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7603
Reviewed-by: sterni <sternenseemann@systemli.org>
Autosubmit: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
2022-12-20 19:08:30 +00:00

18 lines
805 B
BQN
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

lib •Import "../../lib.bqn"
F ¬('-'=lib.IsAsciiNum)
i ˘˘22lib.ReadDec¨>(0<¨/)((F ¯1˙¨(+`F)))¨ •FLines "input"
ssp 4000000
sds (˘˘(+´˘(|(-˝))˘)) i
# _fix is needed to deal with e.g. ⟨0‿15, 5‿8, 12‿23⟩
MergeRanges (())¨(+`((<)»{<´12𝕨𝕩}¨)) lib._fix
Range {cky 𝕊 yxd: x+¯11×d-|cky-y}
RangesY {<˘𝕩(Range˘({cky 𝕊 y·d: d|y-cky}˘/))sds}
OutRangeY {(1<)0˙,𝕩+(ssp×(+1))(1) MergeRanges ssp0RangesY 𝕩}
•Out "day15.1: "•Fmt +´-˜´¨MergeRanges RangesY 2÷˜ssp
•Out "day15.2: "•Fmt +´OutRangeY¨ssp