Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,37 @@
|
|||
import ceylon.random {
|
||||
DefaultRandom
|
||||
}
|
||||
|
||||
shared void run() {
|
||||
value random = DefaultRandom();
|
||||
value range = 1..10;
|
||||
while(true) {
|
||||
value chosen = random.nextElement(range);
|
||||
print("I have chosen a number between ``range.first`` and ``range.last``.
|
||||
What is your guess?");
|
||||
while(true) {
|
||||
if(exists line = process.readLine()) {
|
||||
value guess = Integer.parse(line.trimmed);
|
||||
|
||||
if(is ParseException guess) {
|
||||
print(guess.message);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(guess <=> chosen)
|
||||
case (larger) {
|
||||
print("Too high!");
|
||||
}
|
||||
case (smaller) {
|
||||
print("Too low!");
|
||||
}
|
||||
case (equal) {
|
||||
print("You got it!");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
print("Please enter a number!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
;;(read <default-value> <prompt>) prompts the user with a default value using the browser dialog box.
|
||||
;; we play sounds to make this look like an arcade game
|
||||
(lib 'web) ; (play-sound) is defined in web.lib
|
||||
|
||||
(define (guess-feed (msg " 🔮 Enter a number in [0...100], -1 to stop.") (n (random 100)) (user 0))
|
||||
(set! user (read user msg))
|
||||
(play-sound 'ko)
|
||||
(unless (eq? n user ) ; user is the last user answer
|
||||
(guess-feed
|
||||
(cond ;; adapt prompt according to condition
|
||||
((not (integer? user)) "❌ Please, enter an integer")
|
||||
(( < user 0) (error "🌵 - It was:" n)) ; exit to top level
|
||||
((> n user) "Too low ...")
|
||||
((< n user) "Too high ..."))
|
||||
n user))
|
||||
(play-sound 'ok )
|
||||
" 🔮 Well played!! 🍒 🍇 🍓")
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Randomize
|
||||
Dim n As Integer = Int(Rnd * 20) + 1
|
||||
Dim guess As Integer
|
||||
|
||||
Print "Guess which number I've chosen in the range 1 to 20"
|
||||
Print
|
||||
Do
|
||||
Input " Your guess : "; guess
|
||||
If guess > n AndAlso guess <= 20 Then
|
||||
Print "Your guess is higher than the chosen number, try again "
|
||||
ElseIf guess = n Then
|
||||
Print "Correct, well guessed!"
|
||||
Exit Do
|
||||
ElseIf guess < n AndAlso guess >= 1 Then
|
||||
Print "Your guess is lower than the chosen number, try again"
|
||||
Else
|
||||
Print "Your guess is inappropriate, try again"
|
||||
End If
|
||||
Loop
|
||||
End
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
(defmodule guessing-game
|
||||
(export (main 0)))
|
||||
|
||||
(defun get-player-guess ()
|
||||
(let (((tuple 'ok (list guessed)) (: io fread '"Guess number: " '"~d")))
|
||||
guessed))
|
||||
|
||||
(defun check-guess (answer guessed)
|
||||
(cond
|
||||
((== answer guessed)
|
||||
(: io format '"Well-guessed!!~n"))
|
||||
((/= answer guessed)
|
||||
(if (> answer guessed) (: io format '"Your guess is too low.~n"))
|
||||
(if (< answer guessed) (: io format '"Your guess is too high.~n"))
|
||||
(check-guess answer (get-player-guess)))))
|
||||
|
||||
(defun main ()
|
||||
(: io format '"Guess the number I have chosen, between 1 and 10.~n")
|
||||
(check-guess
|
||||
(: random uniform 10)
|
||||
(get-player-guess)))
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
> (slurp '"guessing-game.lfe")
|
||||
#(ok guessing-game)
|
||||
> (main)
|
||||
Guess the number I have chosen, between 1 and 10.
|
||||
Guess number: 10
|
||||
Your guess is too high.
|
||||
Guess number: 1
|
||||
Your guess is too low.
|
||||
Guess number: 5
|
||||
Your guess is too low.
|
||||
Guess number: 7
|
||||
Well-guessed!!
|
||||
ok
|
||||
>
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/lasso9
|
||||
|
||||
local(
|
||||
lower = integer_random(10, 1),
|
||||
higher = integer_random(100, 20),
|
||||
number = integer_random(#higher, #lower),
|
||||
status = false,
|
||||
guess
|
||||
)
|
||||
|
||||
// prompt for a number
|
||||
stdout('Guess a number: ')
|
||||
|
||||
while(not #status) => {
|
||||
#guess = null
|
||||
|
||||
// the following bits wait until the terminal gives you back a line of input
|
||||
while(not #guess or #guess -> size == 0) => {
|
||||
#guess = file_stdin -> readSomeBytes(1024, 1000)
|
||||
}
|
||||
#guess = integer(#guess)
|
||||
|
||||
if(not (range(#guess, #lower, #higher) == #guess)) => {
|
||||
stdout('Input not of correct type or range. Guess a number: ')
|
||||
else(#guess > #number)
|
||||
stdout('That was to high, try again! ')
|
||||
else(#guess < #number)
|
||||
stdout('That was to low, try again! ')
|
||||
else(#guess == #number)
|
||||
stdout('Well guessed!')
|
||||
#status = true
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
command guessTheNumber lowN highN
|
||||
local tNumber, tguess, tmin, tmax
|
||||
if lowN is empty or lowN < 1 then
|
||||
put 1 into tmin
|
||||
else
|
||||
put lowN into tmin
|
||||
end if
|
||||
if highN is empty then
|
||||
put 10 into tmax
|
||||
else
|
||||
put highN into tmax
|
||||
end if
|
||||
put random(tmax - tmin + 1) + tmin - 1 into tNumber
|
||||
repeat until tguess is tNumber
|
||||
ask question "Please enter a number between" && tmin && "and" && tmax titled "Guess the number"
|
||||
if it is not empty then
|
||||
put it into tguess
|
||||
if tguess is tNumber then
|
||||
answer "Well guessed!"
|
||||
else if tguess < tNumber then
|
||||
answer "too low"
|
||||
else
|
||||
answer "too high"
|
||||
end if
|
||||
else
|
||||
exit repeat
|
||||
end if
|
||||
end repeat
|
||||
end guessTheNumber
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
command testGuessNumber
|
||||
guessTheNumber --defaults to 1-10
|
||||
guessTheNumber 9,12
|
||||
end testGuessNumber
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import random, rdstdin, strutils
|
||||
|
||||
randomize()
|
||||
|
||||
let iRange = 1..100
|
||||
|
||||
echo "Guess my target number that is between ", iRange.a, " and ", iRange.b, " (inclusive)."
|
||||
let target = random(iRange)
|
||||
var answer, i = 0
|
||||
while answer != target:
|
||||
inc i
|
||||
let txt = readLineFromStdin("Your guess " & $i & ": ")
|
||||
try: answer = parseInt(txt)
|
||||
except ValueError:
|
||||
echo " I don't understand your input of '", txt, "'"
|
||||
continue
|
||||
if answer < iRange.a or answer > iRange.b: echo " Out of range!"
|
||||
elif answer < target: echo " Too low."
|
||||
elif answer > target: echo " Too high."
|
||||
else: echo " Ye-Haw!!"
|
||||
|
||||
echo "Thanks for playing."
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import: console
|
||||
|
||||
: guessNumber(a, b)
|
||||
| n g |
|
||||
b a - rand a + 1- ->n
|
||||
begin
|
||||
"Guess a number between" . a . "and" . b . ":" .
|
||||
while(System.Console askln asInteger dup -> g isNull) [ "Not a number " println ]
|
||||
g n == ifTrue: [ "You found it !" .cr return ]
|
||||
g n < ifTrue: [ "Less" ] else: [ "Greater" ] . "than the target" .cr
|
||||
again ;
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
constant lower_limit = 0, upper_limit = 100
|
||||
integer secret = rand(upper_limit-(lower_limit-1))+lower_limit-1
|
||||
printf(1,"Guess the number between %d and %d: ", lower_limit & upper_limit)
|
||||
while 1 do
|
||||
integer guess = prompt_number("", lower_limit & upper_limit)
|
||||
if guess=secret then exit end if
|
||||
printf(1,"Your guess is too %s.\nTry again: ",{iff(guess>secret?"high":"low")})
|
||||
end while
|
||||
puts(1,"You got it!\n")
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
fr = 1 t0 = 10
|
||||
while true
|
||||
see "Hey There,
|
||||
========================
|
||||
I'm thinking of a number between " + fr + " and " + t0 + ", Can you guess it??
|
||||
Guess :> "
|
||||
give x
|
||||
n = nrandom(fr,t0)
|
||||
if x = n see "
|
||||
|
||||
Congratulations :D
|
||||
|
||||
*****************************************************
|
||||
** Your guess was right You Are Genius :D **
|
||||
*****************************************************
|
||||
|
||||
|
||||
"
|
||||
exit
|
||||
else
|
||||
see "Oops its not true, you were just few steps"
|
||||
if x > n see " up :)" else see " down :)" ok
|
||||
see copy(nl,3)
|
||||
ok
|
||||
end
|
||||
|
||||
func nRandom s,e
|
||||
while true
|
||||
d = random(e)
|
||||
if d >= s return d ok
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
var number = rand(1..10);
|
||||
say "Guess the number between 1 and 10";
|
||||
|
||||
loop {
|
||||
given(var n = Sys.scanln("> ").to_i) {
|
||||
when (number) { say "You guessed it."; break }
|
||||
case (n < number) { say "Too low" }
|
||||
default { say "Too high" }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
printf("Lower bound: ");
|
||||
let lowerBound = toint(getline());
|
||||
|
||||
printf("Upper bound: ");
|
||||
let upperBound = toint(getline());
|
||||
|
||||
assert(upperBound > lowerBound, "upper bound must be greater than lower bound");
|
||||
|
||||
seed(time());
|
||||
let n = floor(random() * (upperBound - lowerBound) + lowerBound);
|
||||
var guess;
|
||||
|
||||
print();
|
||||
|
||||
while true {
|
||||
printf("Your guess: ");
|
||||
guess = toint(getline());
|
||||
|
||||
if guess < n {
|
||||
print("too low");
|
||||
} else if guess > n {
|
||||
print("too high");
|
||||
} else {
|
||||
print("You guessed it!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import Cocoa
|
||||
|
||||
var found = false
|
||||
|
||||
let randomNum = Int(arc4random_uniform(100) + 1)
|
||||
|
||||
println("Guess a number between 1 and 100\n")
|
||||
|
||||
while (!found) {
|
||||
var fh = NSFileHandle.fileHandleWithStandardInput()
|
||||
|
||||
println("Enter a number: ")
|
||||
let data = fh.availableData
|
||||
let str = NSString(data: data, encoding: NSUTF8StringEncoding)
|
||||
if (str?.integerValue == randomNum) {
|
||||
found = true
|
||||
println("Well guessed!")
|
||||
} else if (str?.integerValue < randomNum) {
|
||||
println("Good try but the number is more than that!")
|
||||
} else if (str?.integerValue > randomNum) {
|
||||
println("Good try but the number is less than that!")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
decl int high low
|
||||
set low 0
|
||||
set high 100
|
||||
|
||||
out "Guess a number between " low " and " high "." endl endl console
|
||||
decl int target answer i
|
||||
decl ursa.util.random random
|
||||
set target (int (+ 1 (+ low (random.getint (int (- high low))))))
|
||||
while (not (= answer target))
|
||||
inc i
|
||||
out "Your guess(" i "): " console
|
||||
set answer (in int console)
|
||||
|
||||
if (or (< answer low) (> answer high))
|
||||
out " Out of range!" endl console
|
||||
continue
|
||||
end if
|
||||
if (= answer target)
|
||||
out " Ye-Haw!!" endl console
|
||||
continue
|
||||
end if
|
||||
if (< answer target)
|
||||
out " Too low." endl console
|
||||
end if
|
||||
if (> answer target)
|
||||
out " Too high." endl console
|
||||
end if
|
||||
end while
|
||||
|
||||
out endl "Thanks for playing." endl console
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
(defun guessing-game (a b)
|
||||
; minimum and maximum, to be supplied by the user
|
||||
(defun prompt ()
|
||||
(display "What is your guess? ")
|
||||
(define guess (read))
|
||||
(if (eq guess n) ; EQ, unlike =, won't blow up
|
||||
; if GUESS isn't a number
|
||||
(display "Well guessed!")
|
||||
(begin
|
||||
(display
|
||||
(cond
|
||||
((not (integer? guess)) "Come on, that isn't even an integer")
|
||||
((or (< guess a) (> guess b)) "Now you k n o w it won't be that")
|
||||
((< guess n) "Too low")
|
||||
((> guess n) "Too high")))
|
||||
(display "! Try again...")
|
||||
(newline)
|
||||
(prompt))))
|
||||
(define n (+ (random (- (+ b 1) a)) a))
|
||||
(display "I have thought of an integer between ")
|
||||
(display a)
|
||||
(display " and ")
|
||||
(display b)
|
||||
(display ". Try to guess it!")
|
||||
(newline)
|
||||
(prompt))
|
||||
Loading…
Add table
Add a link
Reference in a new issue