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
29
Task/Guess-the-number/ERRE/guess-the-number.erre
Normal file
29
Task/Guess-the-number/ERRE/guess-the-number.erre
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
PROGRAM GUESS_NUMBER
|
||||
|
||||
!
|
||||
! for rosettacode.org
|
||||
!
|
||||
|
||||
BEGIN
|
||||
|
||||
RANDOMIZE(TIMER)
|
||||
N=0
|
||||
R=INT(RND(1)*100+1) ! RND function gives a random number from 0 to 1
|
||||
G=0
|
||||
C$=""
|
||||
|
||||
WHILE G<>R DO
|
||||
INPUT("Pick a number between 1 and 100";G)
|
||||
IF G=R THEN
|
||||
PRINT("You got it!")
|
||||
N+=1
|
||||
PRINT("It took";N;"tries to pick the right Number.")
|
||||
ELSIF G<R THEN
|
||||
PRINT("Try a larger number.")
|
||||
N+=1
|
||||
ELSE
|
||||
PRINT("Try a smaller number.")
|
||||
N+=1
|
||||
END IF
|
||||
END WHILE
|
||||
END PROGRAM
|
||||
14
Task/Guess-the-number/FreeBASIC/guess-the-number.freebasic
Normal file
14
Task/Guess-the-number/FreeBASIC/guess-the-number.freebasic
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Randomize
|
||||
Dim n As Integer = Int(Rnd * 10) + 1
|
||||
Dim guess As Integer
|
||||
Print "Guess which number I've chosen in the range 1 to 10"
|
||||
Print
|
||||
Do
|
||||
Input " Your guess : "; guess
|
||||
If n = guess Then
|
||||
Print "Well guessed!"
|
||||
End
|
||||
End If
|
||||
Loop
|
||||
19
Task/Guess-the-number/LFE/guess-the-number-1.lfe
Normal file
19
Task/Guess-the-number/LFE/guess-the-number-1.lfe
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
(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)
|
||||
(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)))
|
||||
8
Task/Guess-the-number/LFE/guess-the-number-2.lfe
Normal file
8
Task/Guess-the-number/LFE/guess-the-number-2.lfe
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
> (slurp '"guessing-game.lfe")
|
||||
#(ok guessing-game)
|
||||
> (main)
|
||||
Guess the number I have chosen, between 1 and 10.
|
||||
Guess number: 10
|
||||
Guess number: 5
|
||||
Well-guessed!!
|
||||
ok
|
||||
28
Task/Guess-the-number/Lasso/guess-the-number-1.lasso
Normal file
28
Task/Guess-the-number/Lasso/guess-the-number-1.lasso
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
local(
|
||||
number = integer_random(10, 1),
|
||||
status = false,
|
||||
guess
|
||||
)
|
||||
|
||||
// prompt for a number
|
||||
stdout('Guess a number between 1 and 10: ')
|
||||
|
||||
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, 1, 10) == #guess)) => {
|
||||
stdout('Input not of correct type or range. Guess a number between 1 and 10: ')
|
||||
else(#guess == #number)
|
||||
stdout('Well guessed!')
|
||||
#status = true
|
||||
else
|
||||
stdout('You guessed wrong number. Guess a number between 1 and 10: ')
|
||||
}
|
||||
|
||||
}
|
||||
41
Task/Guess-the-number/Lasso/guess-the-number-2.lasso
Normal file
41
Task/Guess-the-number/Lasso/guess-the-number-2.lasso
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?LassoScript
|
||||
|
||||
local(
|
||||
number = integer(web_request -> param('number') or integer_random(10, 1)),
|
||||
status = false,
|
||||
guess = web_request -> param('guess'),
|
||||
_guess = integer(#guess),
|
||||
message = 'Guess a number between 1 and 10'
|
||||
)
|
||||
|
||||
|
||||
|
||||
if(#guess) => {
|
||||
if(not (range(#_guess, 1, 10) == #_guess)) => {
|
||||
#Message = 'Input not of correct type or range. Guess a number between 1 and 10'
|
||||
else(#_guess == #number)
|
||||
#Message = 'Well guessed!'
|
||||
#status = true
|
||||
else
|
||||
#Message = 'You guessed wrong number. Guess a number between 1 and 10'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Guess the number - Rosetta Code</title>
|
||||
</head>
|
||||
<body>
|
||||
<h3>[#message]</h3>
|
||||
[if(not #status)]
|
||||
<form method="post">
|
||||
<label for="guess">Guess:</label><br/ >
|
||||
<input type="number" name="guess" />
|
||||
<input name="number" type="hidden" value="[#number]" />
|
||||
<input name="submit" type="submit" />
|
||||
</form>
|
||||
[/if]
|
||||
</body>
|
||||
</html>
|
||||
15
Task/Guess-the-number/LiveCode/guess-the-number.livecode
Normal file
15
Task/Guess-the-number/LiveCode/guess-the-number.livecode
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
command guessTheNumber
|
||||
local tNumber, tguess
|
||||
put random(10) into tNumber
|
||||
repeat until tguess is tNumber
|
||||
ask question "Please enter a number between 1 and 10" titled "Guess the number"
|
||||
if it is not empty then
|
||||
put it into tguess
|
||||
if tguess is tNumber then
|
||||
answer "Well guessed!"
|
||||
end if
|
||||
else
|
||||
exit repeat
|
||||
end if
|
||||
end repeat
|
||||
end guessTheNumber
|
||||
13
Task/Guess-the-number/Nim/guess-the-number.nim
Normal file
13
Task/Guess-the-number/Nim/guess-the-number.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import strutils, math
|
||||
|
||||
randomize()
|
||||
var chosen = 1 + random(10)
|
||||
echo "I have thought of a number. Try to guess it!"
|
||||
|
||||
var guess = parseInt(readLine(stdin))
|
||||
|
||||
while guess != chosen:
|
||||
echo "Your guess was wrong. Try again!"
|
||||
guess = parseInt(readLine(stdin))
|
||||
|
||||
echo "Well guessed!"
|
||||
5
Task/Guess-the-number/Oforth/guess-the-number.oforth
Normal file
5
Task/Guess-the-number/Oforth/guess-the-number.oforth
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import: console
|
||||
|
||||
: guess
|
||||
10 rand doWhile: [ "Guess :" . System.Console askln asInteger over <> ]
|
||||
drop "Well guessed!" . ;
|
||||
7
Task/Guess-the-number/Phix/guess-the-number.phix
Normal file
7
Task/Guess-the-number/Phix/guess-the-number.phix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
integer secret = rand(10)
|
||||
puts(1,"Guess the number between 1 and 10: ")
|
||||
while 1 do
|
||||
if prompt_number("",{1,10})=secret then exit end if
|
||||
puts(1,"Your guess was wrong.\nTry again: ")
|
||||
end while
|
||||
puts(1,"You got it!\n")
|
||||
31
Task/Guess-the-number/RPL/guess-the-number.rpl
Normal file
31
Task/Guess-the-number/RPL/guess-the-number.rpl
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
DIR
|
||||
INITIALIZE
|
||||
<< { C G R } PURGE RAND 10 * 1 + IP 'R' STO GUESSING
|
||||
>>
|
||||
GUESSING
|
||||
<< "Pick a number between 1 and 10." "" INPUT OBJ-> 'G' STO
|
||||
IF
|
||||
G R ==
|
||||
THEN
|
||||
CLLCD "You got it!" 1 DISP 7 FREEZE 0 WAIT CLLCD CONTINUE
|
||||
ELSE
|
||||
IF
|
||||
G R <
|
||||
THEN
|
||||
CLLCD "Try a larger number." 1 DISP 7 FREEZE 0 WAIT GUESSING
|
||||
ELSE
|
||||
CLLCD "Try a smaller number." 1 DISP 7 FREEZE 0 WAIT GUESSING
|
||||
END
|
||||
END
|
||||
>>
|
||||
CONTINUE
|
||||
<< "Do you want to continue? (0/1)" "" INPUT OBJ-> 'C' STO
|
||||
IF
|
||||
C 1 ==
|
||||
THEN
|
||||
INITIALIZE
|
||||
ELSE
|
||||
CLEAR
|
||||
END
|
||||
>>
|
||||
END
|
||||
17
Task/Guess-the-number/Ring/guess-the-number.ring
Normal file
17
Task/Guess-the-number/Ring/guess-the-number.ring
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
while true
|
||||
see "Hey There,
|
||||
========================
|
||||
I'm thinking of a number between 0 and 10, Can you guess it??
|
||||
Guess :> "
|
||||
give x
|
||||
n = random(10)
|
||||
if x = n see "
|
||||
**********************************************
|
||||
** Thats right You Are Genius :D **
|
||||
**********************************************
|
||||
"
|
||||
exit
|
||||
else
|
||||
see "Oops its not true, Try again please :)" + copy(nl,3)
|
||||
ok
|
||||
end
|
||||
6
Task/Guess-the-number/Sidef/guess-the-number.sidef
Normal file
6
Task/Guess-the-number/Sidef/guess-the-number.sidef
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
var n = 10.rand(1).int;
|
||||
print 'Guess the number: ';
|
||||
while (n != read(Number).int) {
|
||||
print 'Wrong! Guess again: '
|
||||
}
|
||||
say 'Well guessed!';
|
||||
17
Task/Guess-the-number/Swift/guess-the-number.swift
Normal file
17
Task/Guess-the-number/Swift/guess-the-number.swift
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import Cocoa
|
||||
|
||||
var found = false
|
||||
let randomNum = Int(arc4random_uniform(10) + 1)
|
||||
|
||||
println("Guess a number between 1 and 10\n")
|
||||
while (!found) {
|
||||
var fh = NSFileHandle.fileHandleWithStandardInput()
|
||||
|
||||
println("Enter a number: ")
|
||||
let data = fh.availableData
|
||||
var str = NSString(data: data, encoding: NSUTF8StringEncoding)
|
||||
if (str?.integerValue == randomNum) {
|
||||
found = true
|
||||
println("Well guessed!")
|
||||
}
|
||||
}
|
||||
12
Task/Guess-the-number/Ursa/guess-the-number.ursa
Normal file
12
Task/Guess-the-number/Ursa/guess-the-number.ursa
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# Simple number guessing game
|
||||
|
||||
decl ursa.util.random random
|
||||
decl int target guess
|
||||
|
||||
set target (int (+ 1 (random.getint 9)))
|
||||
out "Guess a number between 1 and 10." endl console
|
||||
while (not (= target guess))
|
||||
set guess (in int console)
|
||||
end while
|
||||
|
||||
out "That's right!" endl console
|
||||
9
Task/Guess-the-number/Wortel/guess-the-number.wortel
Normal file
9
Task/Guess-the-number/Wortel/guess-the-number.wortel
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
@let {
|
||||
num 10Wc
|
||||
guess 0
|
||||
[
|
||||
@while != guess num
|
||||
:guess !prompt "Guess the number between 1 and 10 inclusive"
|
||||
!alert "Congratulations!\nThe number was {num}."
|
||||
]
|
||||
}
|
||||
14
Task/Guess-the-number/XLISP/guess-the-number.xlisp
Normal file
14
Task/Guess-the-number/XLISP/guess-the-number.xlisp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(defun guessing-game ()
|
||||
(defun prompt ()
|
||||
(display "What is your guess? ")
|
||||
(define guess (read))
|
||||
(if (= guess n)
|
||||
(display "Well guessed!")
|
||||
(begin
|
||||
(display "No...")
|
||||
(newline)
|
||||
(prompt))))
|
||||
(define n (+ (random 10) 1))
|
||||
(display "I have thought of a number between 1 and 10. Try to guess it!")
|
||||
(newline)
|
||||
(prompt))
|
||||
Loading…
Add table
Add a link
Reference in a new issue