;; File: rdm.lisp ;; Date: 28/08/2010 ;; Author: Collin J. Doering n 0) (pow x (- n 1) (* acc x))) ;; ((< n 0) (pow x (+ n 1) (* acc (/ 1 x)))))) (defun pow (x n) (labels ((pow-helper (x n acc) (cond ((= n 0) acc) ((> n 0) (pow-helper x (- n 1) (* acc x))) ((< n 0) (pow-helper x (+ n 1) (* acc (/ 1 x))))))) (pow-helper x n 1))) (defun bad-factorial (x) (cond ((<= x 0) 1) (T (* x (bad-factorial (- x 1)))))) (defun fib (n) (let ((fib-dot-lst nil)) (labels ((gen-fib (n x) (cond ((> x n) (car fib-dot-lst)) ((= x 0) (setf fib-dot-lst (cons 0 nil)) (gen-fib n (+ x 1))) ((= x 1) (setf fib-dot-lst (cons 1 0)) (gen-fib n (+ x 1))) (t (let* ((fst (car fib-dot-lst)) (scd (cdr fib-dot-lst)) (fibx (+ fst scd))) (setf fib-dot-lst (cons fibx fst)) (gen-fib n (+ x 1))))))) (gen-fib n 0)))) (defun my-cat (pathd) (with-open-file (pathd-in pathd) (loop for line = (read-line pathd-in nil) while line do (format t "~a~%" line)))) (defun average-list (lst &optional (acc 0) (len 0)) (cond ((null lst) (if (> len 0) (/ acc len))) (T (average-list (rest lst) (+ acc (first lst)) (1+ len))))) (defun interval (a b) (labels ((interval-helper (a b &optional (acc nil)) (if (< b a) acc (interval-helper (+ a 1) b (cons a acc))))) (reverse (interval-helper a b)))) ;; broken.. needs complete rewrite ;; (defun prime-seive (a b primes) ;; (let ((a-to-b (interval a b))) ;; (labels ((prime-seive-helper (inter primes &optional (acc nil)) ;; (if inter ;; (loop for p in primes ;; if (divides p (car inter)) ;; do (format t "~a -|- ~a~%" p (car inter)) ;; finally (prime-seive-helper (cdr inter) primes (cons (car inter) acc))) ;; acc))) ;; (prime-seive-helper a-to-b primes))))