J solution (~0.2s runtime on my machine)
Nats =: '0123456789'&(i. ".@:{ ' ' ,~ [)
Claim =: ,"0/&((+ i.@])/)
claims =. |:@(2 2 $ }.)@Nats;._2 fread 'input'
claimed =. <@,@(1000 #:inv Claim)/"2 claims
echo # overlaps =. (~.@#~ -.@~:) ; claimed NB. Part 1
echo >: 0 i.~ overlaps +./@e.S:0 claimed NB. Part 2
BQN solution (~1.9s runtime on my machine)
str ← •Import "strings.bqn"
Claim ← +⌜´ 1000‿1 × ⋈○((⊣+↕∘⊢)´)
claims ← (⍉2‿2⥊1⊸↓∘str.ToNums)¨ •FLines "input"
claimed ← ⥊∘Claim˝¨ claims
•Show ≠ overlaps ← ⍷ ¬∘∊⊸/ ∾ claimed # Part 1
•Show 1+⊑0⊐˜(∨´ overlaps⊸∊)¨ claimed # Part 2
The main slow part is looking for overlaps in the claimed areas
overlaps⊸∊¨ claimed
Technically, the equivlent to J is probably closer to
overlaps ∊⚇1 claimed
but regardless, it's no faster. Additionally, the each-y version in J
(overlaps&e.)@> claimed
is just as fast as Spread (S:
)
dzaima responded:
Alternatively, since the issue is with
𝔽⌜
, I could swap out the+⌜
inClaim
to+⎉0‿∞
which does appear to squeeze the result.