RosettaCodeData/Task/Flipping-bits-game/Uiua/flipping-bits-game.uiua
2026-02-01 16:33:20 -08:00

18 lines
889 B
Text
Raw Permalink 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.

# 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."⧻)⇌