How to resolve the algorithm Guess the number/With feedback (player) step by step in the PicoLisp 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 PicoLisp 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 PicoLisp programming language

Source code in the picolisp programming language

(de guessTheNumber (Min Max)
   (prinl "Think of a number between " Min " and " Max ".")
   (prinl "On every guess of mine you should state whether my guess was")
   (prinl "too high, too low, or equal to your number by typing 'h', 'l', Or '='")
   (use Guess
      (loop
         (NIL (> Max Min)
            (prinl "I think somthing is strange here...") )
         (prin
            "My guess is "
            (setq Guess (+ Min (/ (- Max Min) 2)))
            ",is this correct? " )
         (flush)
         (NIL
            (case (uppc (car (line)))
               ("H" (setq Max Guess))
               ("L" (setq Min Guess))
               ("=" (nil (prinl "I did it!")))
               (T (prinl "I do not understand that...")) ) ) ) ) )

  

You may also check:How to resolve the algorithm Logical operations step by step in the Slate programming language
You may also check:How to resolve the algorithm Read entire file step by step in the SPL programming language
You may also check:How to resolve the algorithm Align columns step by step in the jq programming language
You may also check:How to resolve the algorithm Heronian triangles step by step in the Arturo programming language
You may also check:How to resolve the algorithm Write to Windows event log step by step in the Ruby programming language