added number guesser iterations
This commit is contained in:
parent
a3e07807e8
commit
035ed5abd5
11
src/debug1.a68
Normal file
11
src/debug1.a68
Normal file
@ -0,0 +1,11 @@
|
||||
BEGIN
|
||||
REAL seed_time = seconds;
|
||||
INT seed = ENTIER(seed_time);
|
||||
first random(seed);
|
||||
REAL raw_random = next random;
|
||||
INT random_number = ENTIER(raw_random * 100.0) + 1;
|
||||
print(("seed time : ", seed_time, newline));
|
||||
print(("seed : ", seed, newline));
|
||||
print(("raw random : ", raw_random, newline));
|
||||
print(("random number: ", random_number, newline))
|
||||
END
|
24
src/guess.a68
Normal file
24
src/guess.a68
Normal file
@ -0,0 +1,24 @@
|
||||
BEGIN
|
||||
on logical file end (stand in,
|
||||
(REF FILE f) BOOL: (print(("Goodbye!",new line));stop));
|
||||
|
||||
first random(ENTIER(seconds)); # Seed with current seconds #
|
||||
INT random_number = ENTIER (next random * 100.0) + 1;
|
||||
|
||||
print(("the secret number is",random_number,new line));
|
||||
|
||||
print("guess a number: ");
|
||||
WHILE
|
||||
INT guess = read int;
|
||||
IF guess < random_number THEN
|
||||
print("too low, try again: ");
|
||||
TRUE
|
||||
ELIF guess > random_number THEN
|
||||
print("too high, try again: ");
|
||||
TRUE
|
||||
ELSE
|
||||
print(("that's right",new line));
|
||||
FALSE
|
||||
FI
|
||||
DO SKIP OD
|
||||
END
|
25
src/guess2.a68
Normal file
25
src/guess2.a68
Normal file
@ -0,0 +1,25 @@
|
||||
BEGIN
|
||||
on logical file end (stand in,
|
||||
(REF FILE f) BOOL: (print(("Goodbye!",new line));stop));
|
||||
|
||||
first random(ENTIER(local time)); # Wall-clock seconds #
|
||||
INT random_number = ENTIER(next random * 100.0) + 1;
|
||||
|
||||
print(("seed: ", ENTIER(local time), newline)); # Debug #
|
||||
print(("the secret number is", random_number, newline));
|
||||
|
||||
print("guess a number: ");
|
||||
WHILE
|
||||
INT guess = read int;
|
||||
IF guess < random_number THEN
|
||||
print("too low, try again: ");
|
||||
TRUE
|
||||
ELIF guess > random_number THEN
|
||||
print("too high, try again: ");
|
||||
TRUE
|
||||
ELSE
|
||||
print(("that's right",new line));
|
||||
FALSE
|
||||
FI
|
||||
DO SKIP OD
|
||||
END
|
27
src/guess3.a68
Normal file
27
src/guess3.a68
Normal file
@ -0,0 +1,27 @@
|
||||
BEGIN
|
||||
on logical file end (stand in,
|
||||
(REF FILE f) BOOL: (print(("Goodbye!",new line));stop));
|
||||
|
||||
LONG REAL lt = local time; # Get wall-clock time #
|
||||
INT seed = ENTIER lt; # Convert to integer #
|
||||
first random(seed); # Seed PRNG #
|
||||
INT random_number = ENTIER(next random * 100.0) + 1;
|
||||
|
||||
print(("seed: ", seed, newline));
|
||||
print(("the secret number is", random_number, newline));
|
||||
|
||||
print("guess a number: ");
|
||||
WHILE
|
||||
INT guess = read int;
|
||||
IF guess < random_number THEN
|
||||
print("too low, try again: ");
|
||||
TRUE
|
||||
ELIF guess > random_number THEN
|
||||
print("too high, try again: ");
|
||||
TRUE
|
||||
ELSE
|
||||
print(("that's right",new line));
|
||||
FALSE
|
||||
FI
|
||||
DO SKIP OD
|
||||
END
|
27
src/guess4.a68
Normal file
27
src/guess4.a68
Normal file
@ -0,0 +1,27 @@
|
||||
BEGIN
|
||||
on logical file end (stand in,
|
||||
(REF FILE f) BOOL: (print(("Goodbye!",new line));stop));
|
||||
|
||||
LONG REAL lt = (utc time()); # Get wall-clock time #
|
||||
INT seed = SHORTEN ENTIER lt; # Convert LONG REAL to LONG INT, then INT #
|
||||
first random(seed); # Seed PRNG #
|
||||
INT random_number = ENTIER(next random * 100.0) + 1;
|
||||
|
||||
print(("seed: ", seed, newline));
|
||||
print(("the secret number is", random_number, newline));
|
||||
|
||||
print("guess a number: ");
|
||||
WHILE
|
||||
INT guess = read int;
|
||||
IF guess < random_number THEN
|
||||
print("too low, try again: ");
|
||||
TRUE
|
||||
ELIF guess > random_number THEN
|
||||
print("too high, try again: ");
|
||||
TRUE
|
||||
ELSE
|
||||
print(("that's right",newline));
|
||||
FALSE
|
||||
FI
|
||||
DO SKIP OD
|
||||
END
|
23
src/guess5.a68
Normal file
23
src/guess5.a68
Normal file
@ -0,0 +1,23 @@
|
||||
BEGIN
|
||||
on logical file end (stand in,
|
||||
(REF FILE f) BOOL: (print(("Goodbye!",new line));stop));
|
||||
|
||||
INT random_number = ENTIER(next random * 100.0) + 1; # Generate directly #
|
||||
|
||||
print(("the secret number is", random_number, newline));
|
||||
|
||||
print("guess a number: ");
|
||||
WHILE
|
||||
INT guess = read int;
|
||||
IF guess < random_number THEN
|
||||
print("too low, try again: ");
|
||||
TRUE
|
||||
ELIF guess > random_number THEN
|
||||
print("too high, try again: ");
|
||||
TRUE
|
||||
ELSE
|
||||
print(("that's right",new line));
|
||||
FALSE
|
||||
FI
|
||||
DO SKIP OD
|
||||
END
|
Loading…
Reference in New Issue
Block a user