/ Uiua / 2023 / 08.ua
08.ua
 1  &fras ⊣ &args
 2  
 3  ParseInstructions ← =@R°□⊢
 4  ParseNode         ← ↘1⊢regex"([^ ,]+) = \\(([^ ,]+), ([^ ,]+)\\)"
 5  ParseNetwork      ← ≡ParseNode ↘1
 6  ReplaceNames      ← ⍜⍉(⊗⊃(↘1)⊢)
 7  FindStartAndGoal  ← ∩(⊗□) "AAA","ZZZ"⊢⍉
 8  StartAndGoalMask  ← ∩=@A,@Z≡◇(⊣)⊢⍉
 9  Step              ← ⊃(⊏⊃(⊏◿⧻,⋅⊙⋅⋅∘|⊏⊙⋅⋅∘)|+1⋅∘|⋅⋅⊙⊙∘)
10  Run!              ← ⋅⊙⋅⋅◌ ⍢Step(¬^0) ⊙0
11  LCM               ← ÷◌⊃⍢⊃◿∘±×
12  A                 ← Run!(=⊙⋅∘) FindStartAndGoal
13  B                 ← /LCM ≡(Run!(⊏⊙⋅∘)) ⊓(⊚|¤|¤|¤) StartAndGoalMask
14  
15  ⊜□≠@\n.
16  ⊃ParseNetwork ParseInstructions
17  ⊃B A ⟜ReplaceNames