Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/24-game/Red/24-game-1.red
Normal file
34
Task/24-game/Red/24-game-1.red
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
Red []
|
||||
print "Evaluation from left to right with no precedence, unless you use parenthesis." print ""
|
||||
a: "123456789"
|
||||
guess: ""
|
||||
valid: ""
|
||||
sucess: false
|
||||
random/seed now/time
|
||||
loop 4 [append valid last random a]
|
||||
print ["The numbers are: " valid/1 ", " valid/2 ", " valid/3 " and " valid/4]
|
||||
sort valid
|
||||
insert valid " "
|
||||
|
||||
expr: [term ["+" | "-"] expr | term]
|
||||
term: [primary ["*" | "/"] term | primary]
|
||||
primary: [some digit | "(" expr ")"]
|
||||
digit: charset valid
|
||||
|
||||
while [not sucess] [
|
||||
guess: ask "Enter your expression: "
|
||||
if guess = "q" [halt]
|
||||
numbers: copy guess
|
||||
sort numbers
|
||||
numbers: take/last/part numbers 4
|
||||
insert numbers " "
|
||||
either (parse guess expr) and (valid = numbers) [
|
||||
repeat i length? guess [insert at guess (i * 2) " "]
|
||||
result: do guess
|
||||
print ["The result of your expression is: " result]
|
||||
if (result = 24) [sucess: true]
|
||||
][
|
||||
print "Something is wrong with the expression, try again."
|
||||
]
|
||||
]
|
||||
print "You got it right!"
|
||||
33
Task/24-game/Red/24-game-2.red
Normal file
33
Task/24-game/Red/24-game-2.red
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
Red [
|
||||
Title: "24 Game"
|
||||
Author: "gltewalt"
|
||||
]
|
||||
|
||||
op: charset "*/+-"
|
||||
term: [opt "(" num opt ")"]
|
||||
valid-expression: [term op term op term op term]
|
||||
|
||||
explode: func [val][
|
||||
extract/into val 1 c: copy []
|
||||
]
|
||||
|
||||
check-expression: does [
|
||||
if "q" = e: ask "Enter expression: " [halt]
|
||||
either parse trim/all e valid-expression [
|
||||
either 24 = m: math to-block form explode e [
|
||||
print ["You got it!" m]
|
||||
][
|
||||
print ["Not quite correct. That's" m]]
|
||||
][
|
||||
print "Invalid expression."
|
||||
]
|
||||
]
|
||||
|
||||
main: does [
|
||||
numbers: collect [loop 4 [keep random 9]]
|
||||
num: charset form numbers
|
||||
print [newline "Using the following numbers, enter an expression that equals 24: (pmdas)" numbers]
|
||||
if none? attempt [check-expression][print "Invalid expression."]
|
||||
]
|
||||
|
||||
forever [main]
|
||||
Loading…
Add table
Add a link
Reference in a new issue