Guess the number/With feedback (player): Difference between revisions

Added Easylang
m (syntax highlighting fixup automation)
(Added Easylang)
 
(2 intermediate revisions by 2 users not shown)
Line 1,132:
readln;
end.</syntaxhighlight>
=={{header|EasyLang}}==
{{trans|Ring}}
<syntaxhighlight>
min = 1
max = 100
print "Think of a number between " & min & " and " & max
print "I will try to guess your number."
repeat
guess = (min + max) div 2
print "My guess is " & guess
write "Is it higher than, lower than or equal to your number? "
answer$ = input
print answer$
ans$ = substr answer$ 1 1
until ans$ = "e"
if ans$ = "l"
min = guess + 1
elif ans$ = "h"
max = guess - 1
else
print "Sorry, i didn't understand your answer."
.
.
print "Goodbye."
</syntaxhighlight>
 
=={{header|Elixir}}==
{{works with|Elixir|1.2}}
Line 1,825 ⟶ 1,851:
Is it 1? h
I can't guess it. Perhaps you changed your number.
 
=={{header|jq}}==
''Adapted from [[#Wren|Wren]]''
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq'''
<syntaxhighlight lang=jq>
# Pick an integer from $lowest through $highest ...
def play($lowest; $highest):
# Helper function for guessing
def prompt:
.guess = (((.lowest + .highest)/2)|floor)
| .emit += "\nMy guess is \(.guess)." +
"\nIs this higher/lower than or equal to your chosen number? h/l/e : " ;
"Please choose a number from \($lowest) to \($highest) inclusive and then answer the questions.",
( {$highest, $lowest}
| prompt
| .emit,
( label $out
| foreach inputs as $in (.;
.emit = null
| .hle = ($in|ascii_downcase)
| if .hle == "l" and .guess == .highest
then .emit = "It can't be more than \(highest), try again."
elif .hle == "h" and .guess == .lowest
then .emit = "It can't be less than \(.lowest), try again."
elif .hle == "e"
then .emit = "Good, thanks for playing the game with me!"
| .quit = true
elif .hle == "h"
then if (.highest > .guess - 1) then .highest = .guess - 1
else .
end
elif .hle == "l"
then if (.lowest < .guess + 1) then .lowest = .guess + 1
else .
end
else .emit = "Please try again.\n"
end
| if .quit then ., break $out else prompt end ;
.emit
) ) ) ;
 
def play: play(1;20);
 
play
</syntaxhighlight>
'''Invocation:''' jq -nRr -f guess-the-number-with-feedback-player.jq
{{output}}
<pre>
Please choose a number from 1 to 20 inclusive and then answer the questions.
 
My guess is 10.
Is this higher/lower than or equal to your chosen number? h/l/e :
h
 
My guess is 5.
Is this higher/lower than or equal to your chosen number? h/l/e :
?
Please try again.
 
My guess is 5.
Is this higher/lower than or equal to your chosen number? h/l/e :
0
Please try again.
 
My guess is 5.
Is this higher/lower than or equal to your chosen number? h/l/e :
h
 
My guess is 2.
Is this higher/lower than or equal to your chosen number? h/l/e :
e
Good, thanks for playing the game with me!
$
</pre>
 
=={{header|Julia}}==
Line 3,869 ⟶ 3,971:
{{trans|Kotlin}}
{{libheader|Wren-str}}
<syntaxhighlight lang="ecmascriptwren">import "io" for Stdin, Stdout
import "./str" for Char
 
var hle
2,060

edits