How to resolve the algorithm Guess the number/With feedback step by step in the Clojure programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Guess the number/With feedback step by step in the Clojure programming language
Table of Contents
Problem Statement
Write a game (computer program) that follows the following rules:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Guess the number/With feedback step by step in the Clojure programming language
Source code in the clojure programming language
(defn guess-run []
(let [start 1
end 100
target (+ start (rand-int (inc (- end start))))]
(printf "Guess a number between %d and %d" start end)
(loop [i 1]
(printf "Your guess %d:\n" i)
(let [ans (read)]
(if (cond
(not (number? ans)) (println "Invalid format")
(or (< ans start) (> ans end)) (println "Out of range")
(< ans target) (println "too low")
(> ans target) (println "too high")
:else true)
(println "Correct")
(recur (inc i)))))))
You may also check:How to resolve the algorithm Random number generator (included) step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Loops/Nested step by step in the PL/I programming language
You may also check:How to resolve the algorithm A+B step by step in the RPL programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the EMal programming language
You may also check:How to resolve the algorithm Draw a cuboid step by step in the Python programming language