summaryrefslogtreecommitdiff
path: root/dice.orang
diff options
context:
space:
mode:
Diffstat (limited to 'dice.orang')
-rw-r--r--dice.orang47
1 files changed, 47 insertions, 0 deletions
diff --git a/dice.orang b/dice.orang
new file mode 100644
index 0000000..0fae27b
--- /dev/null
+++ b/dice.orang
@@ -0,0 +1,47 @@
1def dice sides times =
2 let once _ = randInt 1 (sides + 1) in
3 let aux acc times =
4 if times ?= 0 then acc
5 else aux (acc + once ()) (times - 1)
6 in
7 aux 0 times
8
9def guessing_game _ =
10 let secret = randInt 1 101
11 and guessOnce _ = do
12 print "Make your guess: ";
13 let guess = readInt () in
14 if secret > guess then do
15 printLn "My number is larger than that...";
16 false
17 end else if secret < guess then do
18 printLn "My number is smaller than that...";
19 false
20 end else
21 true
22 end
23 and shouldEnd times =
24 if guessOnce () then do
25 printLn "Congratulations! You guessed right!";
26 true
27 end else if times ?= 1 then do
28 printLn "That was your last guess...";
29 true
30 end else do
31 printLn "Guess again...";
32 false
33 end
34 and aux times = do
35 print "You have "; print times; printLn " guesses left";
36 if shouldEnd times then do
37 print "My number was "; printLn secret
38 end else
39 aux (times - 1)
40 end in do
41 printLn "Welcome to the number guessing game";
42 printLn "I will pick a random number between 1 and 100 (inclusive)";
43 printLn " and you try to guess it.";
44 printLn "After each guess, I will tell you if my number was larger or smaller";
45 printLn "Good Luck and Have Fun!";
46 aux 10
47 end