Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Van-Eck-sequence/Common-Lisp/van-eck-sequence-1.lisp
Normal file
19
Task/Van-Eck-sequence/Common-Lisp/van-eck-sequence-1.lisp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
;;Tested using CLISP
|
||||
|
||||
(defun VanEck (x) (reverse (VanEckh x 0 0 '(0))))
|
||||
|
||||
(defun VanEckh (final index curr lst)
|
||||
(if (eq index final)
|
||||
lst
|
||||
(VanEckh final (+ index 1) (howfar curr lst) (cons curr lst))))
|
||||
|
||||
(defun howfar (x lst) (howfarh x lst 0))
|
||||
|
||||
(defun howfarh (x lst runningtotal)
|
||||
(cond
|
||||
((null lst) 0)
|
||||
((eq x (car lst)) (+ runningtotal 1))
|
||||
(t (howfarh x (cdr lst) (+ runningtotal 1)))))
|
||||
|
||||
(format t "The first 10 elements are ~a~%" (VanEck 9))
|
||||
(format t "The 990-1000th elements are ~a~%" (nthcdr 990 (VanEck 999)))
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(defun van-eck-nm-sequence (n m)
|
||||
(loop with ac repeat m
|
||||
for i = (position (car ac) (cdr ac)) do
|
||||
(push (if i (1+ i) 0) ac)
|
||||
finally (return (nthcdr (1- n) (nreverse ac)))))
|
||||
|
||||
(format t "The first 10 elements are: ~{~a ~}~%" (van-eck-nm-sequence 1 10))
|
||||
(format t "The 991-1000th elements are: ~{~a ~}" (van-eck-nm-sequence 991 1000))
|
||||
Loading…
Add table
Add a link
Reference in a new issue