Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Hamming-numbers/Common-Lisp/hamming-numbers-1.lisp
Normal file
20
Task/Hamming-numbers/Common-Lisp/hamming-numbers-1.lisp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(defun next-hamm (factors seqs)
|
||||
(let ((x (apply #'min (map 'list #'first seqs))))
|
||||
(loop for s in seqs
|
||||
for f in factors
|
||||
for i from 0
|
||||
with add = t do
|
||||
(if (= x (first s)) (pop s))
|
||||
;; prevent a value from being added to multiple lists
|
||||
(when add
|
||||
(setf (elt seqs i) (nconc s (list (* x f))))
|
||||
(if (zerop (mod x f)) (setf add nil)))
|
||||
finally (return x))))
|
||||
|
||||
(loop with factors = '(2 3 5)
|
||||
with seqs = (loop for i in factors collect '(1))
|
||||
for n from 1 to 1000001 do
|
||||
(let ((x (next-hamm factors seqs)))
|
||||
(if (or (< n 21)
|
||||
(= n 1691)
|
||||
(= n 1000000)) (format t "~d: ~d~%" n x))))
|
||||
20
Task/Hamming-numbers/Common-Lisp/hamming-numbers-2.lisp
Normal file
20
Task/Hamming-numbers/Common-Lisp/hamming-numbers-2.lisp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(defun hamming (n)
|
||||
(let ((fac '(2 3 5))
|
||||
(idx (make-array 3 :initial-element 0))
|
||||
(h (make-array (1+ n)
|
||||
:initial-element 1
|
||||
:element-type 'integer)))
|
||||
(loop for i from 1 to n
|
||||
with e with x = '(1 1 1) do
|
||||
(setf e (setf (aref h i) (apply #'min x))
|
||||
x (loop for y in x
|
||||
for f in fac
|
||||
for j from 0
|
||||
collect (if (= e y) (* f (aref h (incf (aref idx j)))) y))))
|
||||
(aref h n)))
|
||||
|
||||
(loop for i from 1 to 20 do
|
||||
(format t "~2d: ~d~%" i (hamming i)))
|
||||
|
||||
(loop for i in '(1691 1000000) do
|
||||
(format t "~d: ~d~%" i (hamming i)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue