Pell numbers: Difference between revisions
Content added Content deleted
Line 125: | Line 125: | ||
(do* ((i 0 (1+ i)) |
(do* ((i 0 (1+ i)) |
||
(result (list 1 0)) |
(result (list 1 0)) |
||
(indices nil) |
|||
(b0 0 b1) |
(b0 0 b1) |
||
(b1 1 b2) |
(b1 1 b2) |
||
(b2 (+ (* 2 b1) (* 1 b0)) (+ (* 2 b1) (* 1 b0))) ) |
(b2 (+ (* 2 b1) (* 1 b0)) (+ (* 2 b1) (* 1 b0))) ) |
||
((> (length result) max) (nreverse result)) |
((> (length result) max) (values (nreverse result)(nreverse indices))) |
||
; primep can be any function determining whether a number is prime, for example, |
; primep can be any function determining whether a number is prime, for example, |
||
; https://rosettacode.org/wiki/Primality_by_Wilson%27s_theorem#Common_Lisp |
; https://rosettacode.org/wiki/Primality_by_Wilson%27s_theorem#Common_Lisp |
||
(when (primep b2) |
(when (primep b2) |
||
(push b2 result |
(push b2 result) |
||
(push i indices) ))) |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
Line 163: | Line 165: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
First 7 Pell primes: |
First 7 Pell primes and, as second value, the corresponding indices: |
||
<syntaxhighlight lang="CommonLisp"> |
<syntaxhighlight lang="CommonLisp"> |
||
(pell-primes 7) |
(pell-primes 7) |
||
(0 1 2 5 29 5741 33461 44560482149) ; |
|||
(0 1 3 9 11 27) |
|||
</syntaxhighlight> |
|||
Still missing some of the taks |
Still missing some of the taks |