071.scm 788 B

12345678910111213141516171819202122232425262728
  1. ;; Ordered fractions
  2. (use-modules (euler utils))
  3. (define (prime-gen max-val)
  4. (let loop ((curr-val 2) (acc '()))
  5. (if (> curr-val max-val
  6. ;(ceiling (sqrt max-val))
  7. ) acc
  8. (loop (1+ curr-val)
  9. (if (truth-fold
  10. (lambda (prime) (not (zero? (modulo curr-val prime))))
  11. acc)
  12. (cons curr-val acc)
  13. acc)))))
  14. ;; TODO: this is sub-optimal, we want to alternate between 1+ and 1-
  15. (define (find-frac-left-of frac max-denom)
  16. (let loop ((mult 2) (best-frac 0))
  17. (let ((curr-frac (/ (1- (* mult (numerator frac)))
  18. (* mult (denominator frac)))))
  19. (if (< (- frac curr-frac) (/ (expt max-denom 2)))
  20. best-frac
  21. (loop (1+ mult)
  22. (if (<= (denominator curr-frac) max-denom)
  23. (begin (display curr-frac) (newline)
  24. curr-frac)
  25. best-frac))))))