Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/Babbage-problem/Common-Lisp/babbage-problem-1.lisp
Normal file
6
Task/Babbage-problem/Common-Lisp/babbage-problem-1.lisp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(defun babbage-test (n)
|
||||
"A generic function for any ending of a number"
|
||||
(when (> n 0)
|
||||
(do* ((i 0 (1+ i))
|
||||
(d (expt 10 (1+ (truncate (log n) (log 10))))) )
|
||||
((= (mod (* i i) d) n) i) )))
|
||||
13
Task/Babbage-problem/Common-Lisp/babbage-problem-2.lisp
Normal file
13
Task/Babbage-problem/Common-Lisp/babbage-problem-2.lisp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
; Project : Babbage problem
|
||||
|
||||
(setq n 1)
|
||||
(setq bab2 1)
|
||||
(loop while (/= bab2 269696)
|
||||
do (setq n (+ n 1))
|
||||
(setf bab1 (expt n 2))
|
||||
(setf bab2 (mod bab1 1000000)))
|
||||
(format t "~a" "The smallest number whose square ends in 269696 is: ")
|
||||
(write n)
|
||||
(terpri)
|
||||
(format t "~a" "Its square is: ")
|
||||
(write (* n n))
|
||||
18
Task/Babbage-problem/Common-Lisp/babbage-problem-3.lisp
Normal file
18
Task/Babbage-problem/Common-Lisp/babbage-problem-3.lisp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
;; * The package definition
|
||||
(defpackage :babbage
|
||||
(:use :common-lisp))
|
||||
(in-package :babbage)
|
||||
|
||||
;; * The function
|
||||
(defun babbage (end)
|
||||
"Returns the smallest number whose square ends in END."
|
||||
(loop
|
||||
:with digits = (ceiling (log end 10)) ; How many digits has end?
|
||||
:for num :from (isqrt end) ; The start number
|
||||
:for square = (expt num 2) ; The square of num
|
||||
:for ends = (mod square (expt 10 digits)) ; The last digits
|
||||
:until (= ends end)
|
||||
:finally
|
||||
(format t "The smallest number whose square ends in ~D is: ~D~%" end num)
|
||||
(format t "Its square is: ~D~%" square)
|
||||
(return num)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue