Jump to content

Flipping bits game: Difference between revisions

Added Quackery.
(Added Uiua solution)
(Added Quackery.)
 
Line 5,693:
--------------------------------------------------------------------------------
</syntaxhighlight>
 
=={{header|Quackery}}==
 
<code>transpose</code> is defined at [[Matrix transposition#Quackery]].
 
<syntaxhighlight lang="Quackery"> [ [] 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 --> )</syntaxhighlight>
 
{{out}}
 
As a dialogue in the Quackery shell (REPL).
 
<pre>/O>/O> 3 flipbits
...
Moves: 0
Target
a b c
0: 1 0 0
1: 0 0 1
2: 0 1 0
 
Current
a b c
0: 1 0 1
1: 1 1 1
2: 1 0 0
 
a..., or 0...: a
 
Moves: 1
Target
a b c
0: 1 0 0
1: 0 0 1
2: 0 1 0
 
Current
a b c
0: 0 0 1
1: 0 1 1
2: 0 0 0
 
a..., or 0...: 1
 
Moves: 2
Target
a b c
0: 1 0 0
1: 0 0 1
2: 0 1 0
 
Current
a b c
0: 0 0 1
1: 1 0 0
2: 0 0 0
 
a..., or 0...: 0
 
Moves: 3
Target
a b c
0: 1 0 0
1: 0 0 1
2: 0 1 0
 
Current
a b c
0: 1 1 0
1: 1 0 0
2: 0 0 0
 
a..., or 0...: b
 
Moves: 4
Target
a b c
0: 1 0 0
1: 0 0 1
2: 0 1 0
 
Current
a b c
0: 1 0 0
1: 1 1 0
2: 0 1 0
 
a..., or 0...: 1
 
Moves taken: 5
Stack empty.
 
/O> </pre>
 
=={{header|Racket}}==
1,496

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.