-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday23.ua
41 lines (33 loc) · 1.01 KB
/
day23.ua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Experimental!
~ "git: github.com/amatgil/steal-gift" ~ AoCGet
AoCGet 2024 23
⊜⊜∘⊸∩≠@\n,@-
◴♭₂⟜(⊂⍜⍉⊸⇌⍜♭₂⊛)
Names ←
≡°⊟
Starts ←
Ends ←
Neis ← ▽=Starts:Ends
NeiPaths ← |2 ⨬[[]](/◇⊂≡(≡⊂⟜NeiPaths)⊓Neis-₁)±,
Loops ← ▽=≡⊣,⟜NeiPaths:
Part₁ ← (&p⧻◴≡⍆/◇⊂⍚Loops 3 ⊚=@t≡⊢ Names)
# For part 2, change adjacencies so that
# all nodes are self neighbors
⊸⊂Starts ⇡⧻Names
Starts ←
⊂Ends
Ends ←
Neis ← ▽=Starts:Ends
# Neighborhood intersection
NeiInt ← ∧(▽⊸∊Neis):⇡⧻Names
Part₂ ← (
⇡⧻Names
≡pool°◇°(
# Powerset masks sorted in descending subset size order
:⊏⍖⊸≡/+⋯⇡°ₙ₂⊸⧻NeiInt
# Short-circuit after finding the first subset
# equal to its own neighborhood intersection
⊙⋅◌⍢◌(⍣⊓0(°.⊸NeiInt⊸▽)1:⊙°⊂))
°□⊡⊢⊚=⊸/↥⊸∵◇⧻ wait
&p/⍥₂⊂@,⍆⊏:Names)
⨬Part₁ Part₂ -₁⋕⊡₁&args