Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -0,0 +1,60 @@
[ [] over times
[ over [] swap times
[ 2 random join ]
nested join ]
nip ] is makeboard ( n --> [ )
[ [] swap witheach [ not join ] ] is invert ( [ --> [ )
[ 2dup peek invert unrot poke ] is fliprow ( [ n --> [ )
[ dip transpose fliprow transpose ] is flipcolumn ( [ n --> [ )
[ dup
[ dup size dup * times
[ dup size random
2 random iff
fliprow
else flipcolumn ]
2dup != until ]
nip ] is mix ( [ --> [ )
[ say " "
dup size times
[ sp i^ char a + emit ]
witheach
[ cr sp i^ echo say ":"
witheach
[ sp echo ] ] ] is display ( [ --> )
[ cr $ "a..., or 0...: "
input $ "." join
trim 0 peek lower
2dup char a rot over +
within iff
[ nip char a -
' flipcolumn ]
done
2dup char 0 rot over +
within iff
[ nip char 0 -
' fliprow ]
done
drop again ] is getmove ( n --> n x )
[ 0 temp put
makeboard
dup mix
[ say "Moves: "
temp share echo cr
1 temp tally
2dup swap
say "Target" cr
display cr cr
say "Current" cr
display cr
dup size getmove do cr
2dup = until ]
2drop
temp take
say "Moves taken: " echo ] is flipbits ( n --> )

View file

@ -0,0 +1,19 @@
S ← 9
Fr ← ⊙◌⍜⊡¬⊙.
Fc ← ⊙◌⍉Fr⊙(⍉.)
Shuffle ← ⍥(⟨Fr|Fc⟩<0.5⚂ ⌊×S⚂)×3S
T ← Shuffle ↯S_S 0 # Target setup. Omit `Shuffle` for plain grid.
D ← /+/+⌵-T
# Could use A*, but this is easily solved without it.
# ◌astar(⊂⊃(≡Fr|≡Fc)⇡S¤|÷S D|=0D)
⟜[∘] Shuffle T # Shuffle and keep a copy for the output.
◌⍢(
⊂⊃(≡Fr|≡Fc)⇡S¤ # All neighbours.
⊚=/↧.≡D. # Find min dist, get indices that give that.
⊡⊢ # Pick first one. ⊡(⊡⌊×⚂⧻.) to pick at random.
⊙⊂. # Save a copy of the new state.
| ≠0D
)
⟜($"_ steps."-1⧻)⇌