fork download
  1. ; trabb pardo-knuth algorithm
  2.  
  3. (define (tpk len)
  4. (define (f x) (+ (sqrt (abs x)) (* 5 x x x)))
  5. (let loop ((len len) (nums '()))
  6. (if (positive? len)
  7. (loop (- len 1) (cons (read) nums))
  8. (for-each
  9. (lambda (x)
  10. (let ((result (f x)))
  11. (display (if (< 400 result) "TOO LARGE" result))
  12. (newline)))
  13. nums))))
  14.  
  15. (tpk 11)
  16.  
  17. (define (read-number len)
  18. (let ((vec (make-vector len 0)))
  19. (do ((i 0 (+ i 1)) (num (read) (read)))
  20. ((or (= i len)(eof-object? num)) vec)
  21. (vector-set! vec i num))))
  22.  
  23. (define (vector-reverse vec)
  24. (do ((lo 0 (+ lo 1))
  25. (hi (- (vector-length vec) 1) (- hi 1)))
  26. ((<= hi lo) vec)
  27. (let ((t (vector-ref vec lo)))
  28. (vector-set! vec lo (vector-ref vec hi))
  29. (vector-set! vec hi t))))
  30.  
  31. (define (f num) (+ (sqrt (abs num)) (* 5 num num num)))
  32.  
  33. (define (tpk len)
  34. (let ((vec (vector-reverse (read-number len))))
  35. (do ((i 0 (+ i 1))) ((= i len))
  36. (let ((result (f (vector-ref vec i))))
  37. (display (if (< 400 result) "TOO LARGE" result))
  38. (newline)))))
  39.  
  40. (tpk 11)
Success #stdin #stdout 0.03s 4176KB
stdin
-5 -4 -3 -2 -1 0 1 2 3 4 5
-5 -4 -3 -2 -1 0 1 2 3 4 5
stdout
TOO LARGE
322.0
136.732050807569
41.4142135623731
6.0
0.0
-4.0
-38.5857864376269
-133.267949192431
-318.0
-622.7639320225
TOO LARGE
322.0
136.732050807569
41.4142135623731
6.0
0.0
-4.0
-38.5857864376269
-133.267949192431
-318.0
-622.7639320225