24 game/Solve: Difference between revisions

Added Quackery.
m (→‎{{header|C sharp}}: Regularize header markup to recommended on category page)
(Added Quackery.)
Line 7,343:
root.mainloop()
</lang>
 
=={{header|Quackery}}==
 
<code>permutations</code> is defined at [[Permutations#Quackery]] and <code>uniquewith</code> is defined at [[Remove duplicate elements#Quackery]].
 
<lang Quackery> [ ' [ 0 1 2 3 ]
permutations ] constant is numorders ( --> [ )
 
[ []
4 3 ** times
[ [] i^
3 times
[ 4 /mod 4 +
rot join swap ]
drop
nested join ] ] constant is oporders ( --> [ )
 
[ [] numorders witheach
[ oporders witheach
[ dip dup join nested
rot swap join swap ]
drop ] ] constant is allorders ( --> [ )
 
[ [] unrot witheach
[ dip dup peek
swap dip [ nested join ] ]
drop ] is reorder ( [ [ --> [ )
 
[ ' [ [ 0 1 4 2 5 3 6 ]
[ 0 1 4 2 3 5 6 ]
[ 0 1 2 4 3 5 6 ] ]
witheach
[ dip dup reorder swap ]
4 pack ] is orderings ( [ --> [ )
 
[ witheach
[ dup number? iff n->v done
dup ' + = iff
[ drop v+ ] done
dup ' - = iff
[ drop v- ] done
' * = iff v* done
v/ ]
24 n->v v- v0= ] is 24= ( [ --> b )
 
[ 4 pack sort
[] swap
' [ + - * / ] join
allorders witheach
[ dip dup reorder orderings
witheach
[ dup 24= iff
[ rot swap
nested join swap ]
else drop ] ]
drop
uniquewith
[ unbuild swap unbuild $< ]
dup size
dup 0 = iff
[ 2drop say "No solutions." ]
done
dup 1 = iff
[ drop say "1 solution." ]
else
[ echo say " solutions." ]
unbuild
2 split nip
-2 split drop nest$ 90 wrap$ ] is solve ( n n n n --> )</lang>
 
{{out}}
 
As a dialogue in the Quackery shell.
 
<pre>/O> 8 8 3 3 solve
...
1 solution.
[ 8 3 8 3 / - / ]
Stack empty.
 
/O> 7 7 9 4 solve
...
No solutions.
Stack empty.
 
/O> 8 7 6 5 solve
...
22 solutions.
[ 5 7 + 8 6 - * ] [ 5 7 + 8 - 6 * ] [ 5 8 - 7 + 6 * ] [ 6 5 7 8 - + * ] [ 6 5 7 + 8 - * ]
[ 6 5 8 7 - - * ] [ 6 5 8 - 7 + * ] [ 6 7 5 8 - + * ] [ 6 7 5 + 8 - * ] [ 6 7 5 - 8 / / ]
[ 6 7 8 5 - - * ] [ 6 7 8 - 5 + * ] [ 6 8 7 5 - / * ] [ 6 8 * 7 5 - / ] [ 7 5 + 8 6 - * ]
[ 7 5 + 8 - 6 * ] [ 7 8 - 5 + 6 * ] [ 8 6 7 5 - / * ] [ 8 6 - 5 7 + * ] [ 8 6 - 7 5 + * ]
[ 8 6 * 7 5 - / ] [ 8 7 5 - 6 / / ]
Stack empty.
</pre>
 
 
=={{header|R}}==
1,462

edits