[ create a new paste ] login | about

Project: programmingpraxis
Link: http://programmingpraxis.codepad.org/8OFS3rH7    [ raw code | fork ]

programmingpraxis - Scheme, pasted on Apr 25:
; trabb pardo-knuth algorithm
 
(define (tpk len)
  (define (f x) (+ (sqrt (abs x)) (* 5 x x x)))
  (let loop ((len len) (nums '()))
    (if (positive? len)
        (loop (- len 1) (cons (read) nums))
        (for-each
          (lambda (x)
            (let ((result (f x)))
              (display (if (< 400 result) "TOO LARGE" result))
              (newline)))
          nums))))
 
(tpk 11)
 
(define (read-number len)
  (let ((vec (make-vector len 0)))
    (do ((i 0 (+ i 1)) (num (read) (read)))
        ((or (= i len)(eof-object? num)) vec)
      (vector-set! vec i num))))
 
(define (vector-reverse vec)
  (do ((lo 0 (+ lo 1))
       (hi (- (vector-length vec) 1) (- hi 1)))
      ((<= hi lo) vec)
    (let ((t (vector-ref vec lo)))
      (vector-set! vec lo (vector-ref vec hi))
      (vector-set! vec hi t))))
 
(define (f num) (+ (sqrt (abs num)) (* 5 num num num)))
 
(define (tpk len)
  (let ((vec (vector-reverse (read-number len))))
    (do ((i 0 (+ i 1))) ((= i len))
      (let ((result (f (vector-ref vec i))))
        (display (if (< 400 result) "TOO LARGE" result))
        (newline)))))
 
(tpk 11)


Create a new paste based on this one


Comments: