How to resolve the algorithm Guess the number/With feedback (player) step by step in the Ring programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Guess the number/With feedback (player) step by step in the Ring programming language
Table of Contents
Problem Statement
Write a player for the game that follows the following rules: The computer should guess intelligently based on the accumulated scores given. One way is to use a Binary search based algorithm.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Guess the number/With feedback (player) step by step in the Ring programming language
Source code in the ring programming language
min = 1
max = 100
see "think of a number between " + min + " and " + max + nl
see "i will try to guess your number." + nl
while true
guess =floor((min + max) / 2)
see "my guess is " + guess + nl
see "is it higher than, lower than or equal to your number " give answer
ans = left(answer,1)
switch ans
on "l" min = guess + 1
on "h" max = guess - 1
on "e" exit
other see "sorry, i didn't understand your answer." + nl
off
end
see "goodbye." + nl
You may also check:How to resolve the algorithm Wordiff step by step in the Phix programming language
You may also check:How to resolve the algorithm Totient function step by step in the RPL programming language
You may also check:How to resolve the algorithm Associative array/Creation step by step in the Ruby programming language
You may also check:How to resolve the algorithm Phrase reversals step by step in the Maple programming language
You may also check:How to resolve the algorithm Attractive numbers step by step in the Arturo programming language