Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/24-game/Mathematica/24-game.math
Normal file
15
Task/24-game/Mathematica/24-game.math
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
isLegal[n_List, x_String] :=
|
||||
Quiet[Check[
|
||||
With[{h = ToExpression[x, StandardForm, HoldForm]},
|
||||
If[Cases[Level[h, {2, \[Infinity]}, Hold, Heads -> True],
|
||||
Except[_Integer | Plus | _Plus | Times | _Times | Power |
|
||||
Power[_, -1]]] === {} &&
|
||||
Sort[Level[h /. Power[q_, -1] -> q, {-1}] /.
|
||||
q_Integer -> Abs[q]] === Sort[n], ReleaseHold[h]]], Null]]
|
||||
Grid[{{Button[
|
||||
"new numbers", {a, b, c, d} = Table[RandomInteger[{1, 9}], {4}]],
|
||||
InputField[Dynamic[x], String]}, {Dynamic[{a, b, c, d}],
|
||||
Dynamic[Switch[isLegal[{a, b, c, d}, x], Null,
|
||||
"Sorry, that is invalid.", 24, "Congrats! That's 24!", _,
|
||||
"Sorry, that makes " <> ToString[ToExpression@x, InputForm] <>
|
||||
", not 24."]]}}]
|
||||
Loading…
Add table
Add a link
Reference in a new issue