Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
66
Task/24-game/MiniScript/24-game.mini
Normal file
66
Task/24-game/MiniScript/24-game.mini
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
evalAddSub = function()
|
||||
result = evalMultDiv
|
||||
while true
|
||||
if not tokens then return result
|
||||
op = tokens[0]
|
||||
if op != "+" and op != "-" then return result
|
||||
tokens.pull // (discard operator)
|
||||
rhs = evalMultDiv
|
||||
if result == null or rhs == null then return null
|
||||
if op == "+" then result = result + rhs
|
||||
if op == "-" then result = result - rhs
|
||||
end while
|
||||
end function
|
||||
|
||||
evalMultDiv = function()
|
||||
result = evalAtom
|
||||
while true
|
||||
if not tokens then return result
|
||||
op = tokens[0]
|
||||
if op != "*" and op != "/" then return result
|
||||
tokens.pull // (discard operator)
|
||||
rhs = evalAtom
|
||||
if result == null or rhs == null then return null
|
||||
if op == "*" then result = result * rhs
|
||||
if op == "/" then result = result / rhs
|
||||
end while
|
||||
end function
|
||||
|
||||
evalAtom = function()
|
||||
if tokens[0] == "(" then
|
||||
tokens.pull
|
||||
result = evalAddSub
|
||||
if not tokens or tokens.pull != ")" then
|
||||
print "Unbalanced parantheses"
|
||||
return null
|
||||
end if
|
||||
return result
|
||||
end if
|
||||
num = val(tokens.pull)
|
||||
idx = availableDigits.indexOf(num)
|
||||
if idx == null then
|
||||
print str(num) + " is not available"
|
||||
return null
|
||||
else
|
||||
availableDigits.remove idx
|
||||
end if
|
||||
return num
|
||||
end function
|
||||
|
||||
choices = []
|
||||
for i in range(1, 4)
|
||||
choices.push ceil(rnd*9)
|
||||
end for
|
||||
result = null
|
||||
while result != 24
|
||||
availableDigits = choices[:] // (clones the list)
|
||||
print "Using only the digits " + availableDigits + ","
|
||||
tokens = input("enter an expression that comes to 24: ").replace(" ","").values
|
||||
result = evalAddSub
|
||||
if availableDigits then
|
||||
print "You forgot to use: " + availableDigits
|
||||
result = null
|
||||
end if
|
||||
if result != null then print "That equals " + result + "."
|
||||
end while
|
||||
print "Great job!"
|
||||
Loading…
Add table
Add a link
Reference in a new issue