Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
69
Task/24-game/EasyLang/24-game.easy
Normal file
69
Task/24-game/EasyLang/24-game.easy
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
print "Enter an equation in RPN form using all of, and"
|
||||
print "only the following single digits which evaluates"
|
||||
print "to 24. Only '*', '/', '+' and '-' are allowed:"
|
||||
func game .
|
||||
len cnt[] 9
|
||||
write ">> "
|
||||
for i to 4
|
||||
h = random 9
|
||||
write h & " "
|
||||
cnt[h] += 1
|
||||
.
|
||||
print ""
|
||||
s$ = input
|
||||
print s$
|
||||
if s$ = ""
|
||||
return 1
|
||||
.
|
||||
for c$ in strchars s$
|
||||
if c$ = "+" or c$ = "-" or c$ = "*" or c$ = "/"
|
||||
if len st[] < 2
|
||||
print "Stack empty"
|
||||
return 1
|
||||
.
|
||||
if c$ = "+"
|
||||
st[$ - 1] = st[$ - 1] + st[$]
|
||||
elif c$ = "-"
|
||||
st[$ - 1] = st[$ - 1] - st[$]
|
||||
elif c$ = "*"
|
||||
st[$ - 1] = st[$ - 1] * st[$]
|
||||
else
|
||||
st[$ - 1] = st[$ - 1] / st[$]
|
||||
.
|
||||
len st[] -1
|
||||
elif c$ <> " "
|
||||
h = strcode c$ - 48
|
||||
if h < 1 or h > 9
|
||||
print "Wrong command " & c$
|
||||
return 0
|
||||
.
|
||||
if cnt[h] = 0
|
||||
print "Wrong number " & h
|
||||
return 0
|
||||
.
|
||||
cnt[h] -= 1
|
||||
st[] &= h
|
||||
.
|
||||
.
|
||||
for c in cnt[]
|
||||
s += c
|
||||
.
|
||||
if s > 0
|
||||
print "Not all numbers used"
|
||||
return 0
|
||||
.
|
||||
if len st[] > 1
|
||||
print "Calculation not finished"
|
||||
return 0
|
||||
.
|
||||
print st[1]
|
||||
if abs (st[1] - 24) < 1e-10
|
||||
print "Well done"
|
||||
else
|
||||
print "Wrong result"
|
||||
.
|
||||
.
|
||||
repeat
|
||||
print ""
|
||||
until game = 1
|
||||
.
|
||||
Loading…
Add table
Add a link
Reference in a new issue