18 lines
889 B
Text
18 lines
889 B
Text
# Could use `path`, but this is easily solved without it.
|
||
# ⊢path(⊂⊃(≡Fr|≡Fc)⇡Size¤|=0Dist|÷Size Dist) Shuffle T
|
||
|
||
Size ← 8
|
||
T ← ↯Size_Size 0 # Simple target setup.
|
||
Fr ← ⍜⊡¬⊙ # Flip a row.
|
||
Fc ← ⍜⊙⍉Fr # Flip a col.
|
||
Shuffle ← ⍥(⨬(Fr|Fc)<0.5⚂ ⌊×⚂Size)××2.Size # Apply random changes.
|
||
Dist ← /+/+⌵-T # Number of wrong cells.
|
||
⟜[∘]Shuffle T # Shuffle and start a copy for the output.
|
||
◌⍢(
|
||
⊂⊃(≡Fr|≡Fc)⇡Size¤ # All neighbours.
|
||
⊚=/↧.≡Dist. # Find min dist, get indices that give that.
|
||
⊡⊢ # Pick first one.
|
||
⊙⊂. # Save a copy of the new state.
|
||
| ≠0Dist # Repeat until found target.
|
||
)
|
||
⟜($"_ steps."⧻)⇌
|