最後活躍 6 days ago Unlisted

translated from wul

修訂 5d84c0d4ced729a619752ceef427e3392ee95c42

gistfile1.txt 原始檔案 Playground
1|| :comment: play a guessing game from 1 to 100
2
3| :: play a guessing game from $min to $max |
4:: . pick a number from $min to $max
5 . begin game loop
6
7| :: begin game loop |
8 :print: "enter a guess"
9:: .read a number
10 . compare guess with target
11 . decide on next step
12
13| :: pick a number from $min to $max |
14 :target: $n
15 :@js: $n = tostring(Math.floor(Math.random() * (@max - @min) + @min))
16
17| :: read a number |
18 :guess: $n :@js:
19 repeat
20 $n = io.read(\"*line\")
21 until tonumber($n)
22 $n = tostring(tonumber($n))
23
24| :: compare guess with target :guess: $n :target: $n |
25 :state: win
26
27| :: compare guess with target :guess: $n :target: $m |
28 :state: $state :target: $m :@js: "
29 if tonumber($n) < tonumber($m) then
30 $state = \"too low\"
31 else
32 $state = \"too high\"
33 end
34 "
35
36|:: decide on next step :state: "win" |
37 :print: "you win!"
38
39| decide on next step :state: $s |
40 :print: $s
41 :: begin game loop
42
43| :print: $message |
44 :@js: print($message)