Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,5 @@
(define (fibonacci n)
(let (L '(0 1))
(dotimes (i n)
(setq L (list (L 1) (apply + L))))
(L 1)) )

View file

@ -0,0 +1,4 @@
(define (fibonacci n)
(if (< n 2) 1
(+ (fibonacci (- n 1))
(fibonacci (- n 2)))))

View file

@ -0,0 +1,7 @@
(define (fibonacci n)
(letn (f '((0 1) (1 1)) fib f)
(dotimes (i n)
(set 'fib (multiply fib f)))
(fib 0 1)) )
(print(fibonacci 10)) ;;89

View file

@ -0,0 +1,15 @@
;;; Global variable (bigints); can be isolated in a namespace if need be
(setq stack '(0L 1L))
;
;;; If the stack is too short, complete it; then read from it
;;; Adding at the end of a list is optimized in NewLisp
(define (fib n)
(while (<= (length stack) n)
(push (+ (stack -1) (stack -2)) stack -1))
(stack n))
;
;;; Test (~ 7+ s on my mediocre laptop)
;(println (time (fib 50000)))
;;; or
(println (length (fib 50000)))
;;; outputs 10450 (digits)