Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Hailstone-sequence/Common-Lisp/hailstone-sequence.lisp
Normal file
11
Task/Hailstone-sequence/Common-Lisp/hailstone-sequence.lisp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(defun hailstone (n)
|
||||
(cond ((= n 1) '(1))
|
||||
((evenp n) (cons n (hailstone (/ n 2))))
|
||||
(t (cons n (hailstone (+ (* 3 n) 1))))))
|
||||
|
||||
(defun longest (n)
|
||||
(let ((k 0) (l 0))
|
||||
(loop for i from 1 below n do
|
||||
(let ((len (length (hailstone i))))
|
||||
(when (> len l) (setq l len k i)))
|
||||
finally (format t "Longest hailstone sequence under ~A for ~A, having length ~A." n k l))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue