Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/24-game/Picat/24-game.picat
Normal file
30
Task/24-game/Picat/24-game.picat
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import util.
|
||||
|
||||
main =>
|
||||
play.
|
||||
|
||||
play =>
|
||||
nl,
|
||||
Digits = [random() mod 9 + 1 : _ in 1..4].sort(),
|
||||
println("Enter \"q\" to quit"),
|
||||
println("Enter \"!\" to request a new set of four digits."),
|
||||
printf("Or enter expression using %w => ", Digits),
|
||||
Exp = read_line().strip(),
|
||||
evaluate(Digits,Exp).
|
||||
|
||||
evaluate(_Digits,"q") => halt.
|
||||
evaluate(_Digits,"!") => play.
|
||||
evaluate(Digits,Exp) =>
|
||||
Operands = [to_int(D) : D in Exp, digit(D)].sort(),
|
||||
(Digits !== Operands ->
|
||||
println("You must use the given digits:" ++ to_string(Digits))
|
||||
;
|
||||
catch(Term = parse_term(Exp), Exception, println(Exception)),
|
||||
Res is Term,
|
||||
(Res =:= 24 ->
|
||||
println("Good work!")
|
||||
;
|
||||
println("Wong expression")
|
||||
)
|
||||
),
|
||||
play.
|
||||
Loading…
Add table
Add a link
Reference in a new issue