;;; ================================================================= ;;; ;; This is bad. However, the rest of this file keeps breaking during ;; `load' in SCM, I think due to stinky SCM installations on my ;; machines. Since the main reason I load this file is to compute ;; prime factors of [relatively] small numbers, these awful, ;; unsophisticated, but *terrifyingly portable* tester routines will ;; at least be in the environment before the load breaks. (define upping (lambda (target start) (cond ((> start target) '()) ((= start target) (list start)) ((integer? (/ target start)) (cons start (upping (/ target start) 3))) (#t (upping target (+ start 2)))))) (define factorize (lambda (x) (upping x 3))) (define prime? (lambda (x) (= (length (factorize x)) 1))) ;;; ================================================================= ;;; ;; Okay, now a somewhat better algorithm. (load-option 'format) (define rec (lambda (candidate root d) (if (> d root) #t (if (zero? (modulo candidate d)) (begin (write-string (format #f "candidate was: ~A" d))) (rec candidate root (+ d 2)))))) (define prime? (lambda (n) (if (zero? (modulo n 2)) #f (let ((root (sqrt n))) (rec n root 3))))) ; (define karl-seq ; (lambda (x) ; (if (zero? x) ; 0 ; (let seq ((n 1)) ; (if (= n (- x 1)) ; (list n) ; (cons (* n (- x n)) (seq (+ n 1)))))))) ; ; (define var-pascal ; (lambda (left right last-row) ; (let do-it ((l (list (list left right))) (last-row last-row)) ; (if (zero? last-row) ; l ; (do-it (cons (cross (car l)) l) (- last-row 1)))))) ; ; (define cross ; (lambda (l) ; l is a lat of numbers ; (cons (car l) )))