How to resolve the algorithm Babbage problem step by step in the Clojure programming language
How to resolve the algorithm Babbage problem step by step in the Clojure programming language
Table of Contents
Problem Statement
Charles Babbage, looking ahead to the sorts of problems his Analytical Engine would be able to solve, gave this example: He thought the answer might be 99,736, whose square is 9,947,269,696; but he couldn't be certain.
The task is to find out if Babbage had the right answer — and to do so, as far as your language allows it, in code that Babbage himself would have been able to read and understand. As Babbage evidently solved the task with pencil and paper, a similar efficient solution is preferred. For these purposes, Charles Babbage may be taken to be an intelligent person, familiar with mathematics and with the idea of a computer; he has written the first drafts of simple computer programmes in tabular form. [Babbage Archive Series L].
The aim of the task is to write a program that is sufficiently clear and well-documented for such a person to be able to read it and be confident that it does indeed solve the specified problem.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Babbage problem step by step in the Clojure programming language
Source code in the clojure programming language
; Defines function named babbage? that returns true if the
; square of the provided number leaves a remainder of 269,696 when divided
; by a million
(defn babbage? [n]
(let [square (* n n)]
(= 269696 (mod square 1000000))))
; Use the above babbage? to find the first positive integer that returns true
; (We're exploiting Clojure's laziness here; (range) with no parameters returns
; an infinite series.)
(first (filter babbage? (range)))
You may also check:How to resolve the algorithm Bitwise operations step by step in the Slate programming language
You may also check:How to resolve the algorithm Random numbers step by step in the Lua programming language
You may also check:How to resolve the algorithm Character codes step by step in the PHP programming language
You may also check:How to resolve the algorithm Yahoo! search interface step by step in the Tcl programming language
You may also check:How to resolve the algorithm Read entire file step by step in the Standard ML programming language