Anonymous user
24 game: Difference between revisions
→{{header|PicoLisp}}
m (GOTO reference changed at end of game, to ensure control returns to correct beginning.) |
|||
Line 8,022:
=={{header|PicoLisp}}==
<lang PicoLisp>
(de random4digits ()
(make▼
(when (diff Lst (fish num? Exe))▼
(link "Not all numbers used" ) )▼
(when (diff (fish num? Exe) Lst)▼
(link "Using wrong number(s)") )▼
(when (diff (fish sym? Exe) '(+ - * /))▼
(link "Using illegal operator(s)") ) ) )▼
(loop▼
(setq Numbers (make (do 4 (link (rand 1 9)))))
"Please enter a Lisp expression using (, ), +, -, *, / and "▼
(T (= "." (setq Reply (catch '(NIL) (in NIL (read)))))▼
(bye) )▼
((str? Reply)▼
(prinl "-- Illegal Expression")▼
(for S @▼
(space 3)▼
(prinl S) ) )▼
(prinl "++ Congratulations! Correct result :-)") )▼
{{out}}▼
<pre>Please enter a Lisp expression using (, ), +, -, *, / and 1, 3, 3, 5▼
++ Congratulations! Correct result :-)▼
(de prompt ()
Please enter a Lisp expression using (, ), +, -, *, / and 8, 4, 7, 1▼
(prinl "Please enter a 'Lisp' expression that equals 24 using (, ), +, -, *, / and " Numbers) )
-- Illegal Expression▼
Not all numbers used▼
Using wrong number(s)▼
Using illegal operator(s)▼
(de getinput ()
Please enter a Lisp expression using (, ), +, -, *, / and 4, 2, 2, 3▼
(de checkexpression (Numbers Expression)
Please enter a Lisp expression using (, ), +, -, *, / and 8, 4, 5, 9▼
▲ (make
▲ (link "Using illegal operator(s).") ) ) )
(de loopuntilquit ()
(prinl "Example 'Lisp' expression: (+ (* 4 5) (- 1 2))")
▲ (loop
(set 'Numbers (random4digits))
(set 'Expression (getinput))
(if (= Expression ".") (prog (prinl "bye!") (bye)))
(set 'Check (checkexpression Numbers Expression))
(prinl "That evaluated to " Evaluated " Try again!") ) ) ) ) )
(loopuntilquit)
</lang>
▲{{out}}
<pre>
pil 24game.l +
Example 'Lisp' expression: (+ (* 4 5) (- 1 2))
(+ 1 3)
(+ 3 9)
Not all numbers used.
(^ 2 7 1 3)
(* (* 3 8) (- 7 6))
.
bye!
</pre>
=={{header|PL/I}}==
|