diff options
| author | Mistivia <i@mistivia.com> | 2024-11-09 01:26:37 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2024-11-09 01:35:37 +0800 |
| commit | 37be9418ad8f5bbde5f7b703115a2d4fb5d6185e (patch) | |
| tree | 88888561c98ca9e459ca9978a8fd79ae5aec2b0a | |
| parent | ab11ad9a8b6cf46131620a49486e91656b9d913b (diff) | |
2 Even Fibonacci Numbers
| -rwxr-xr-x[-rw-r--r--] | 0001/main.lisp | 6 | ||||
| -rw-r--r-- | 0002/main.lisp | 19 |
2 files changed, 22 insertions, 3 deletions
diff --git a/0001/main.lisp b/0001/main.lisp index c7ba165..0ce3d1d 100644..100755 --- a/0001/main.lisp +++ b/0001/main.lisp @@ -1,13 +1,13 @@ (defun genlist (n) (defun impl (x lst) (if (> x n) - (reverse lst) - (impl (+ 1 x) (cons x lst)))) + (reverse lst) + (impl (+ 1 x) (cons x lst)))) (impl 1 '())) (let ((sum 0)) (loop for x in (genlist 999) - do (if (or (equal 0 (mod x 3)) + do (if (or (equal 0 (mod x 3)) (equal 0 (mod x 5))) (setf sum (+ sum x)))) (print sum)) diff --git a/0002/main.lisp b/0002/main.lisp new file mode 100644 index 0000000..df3e1cd --- /dev/null +++ b/0002/main.lisp @@ -0,0 +1,19 @@ +(defun new-next-fibo-generator () + (let ((x0 0) + (x1 1)) + (lambda () + (let ((next (+ x0 x1))) + (setf x0 x1) + (setf x1 next) + next)))) + +(defvar *uplimit* 4000000) + +(let ((next-fibo (new-next-fibo-generator)) + (sum 0)) + (do ((x (funcall next-fibo) (funcall next-fibo))) + ((> x *uplimit*) sum) + (setf sum (if (evenp x) + (+ sum x) + sum))) + (format t "~&~S" sum)) |
