p108.scm 913 B

1234567891011121314151617181920212223242526272829
  1. ;; Diophantine reciprocals I
  2. ;; It seems that there is repetition that I can take advantage of!
  3. ;; I don't actually need to go that high, since it seems every prime number starts with three, and then every time I double it, then we are good!
  4. (define-module (unsolved p108))
  5. (define (least-n=>distinct-solutions>k solution-proc k)
  6. (let lp ([n 2] [curr-soltn (solution-proc 2)])
  7. (if (> curr-soltn k) n
  8. (lp (1+ n) (solution-proc (1+ n))))))
  9. (define (distinct-diophantine-reciprocals n)
  10. (let lp ([i (1+ n)] [max-denom (inf)] [acc 0])
  11. (if (> i max-denom)acc
  12. (let ([val (diophantine-diff i n)])
  13. ; (display (/ 1 i))
  14. ; (display " ")
  15. ; (display val)
  16. ; (newline)
  17. (if (= 1 (numerator val))
  18. (lp (1+ i)
  19. (if (< (denominator val) max-denom)
  20. (denominator val) max-denom)
  21. (1+ acc))
  22. (lp (1+ i) max-denom acc))))))
  23. (define (diophantine-diff x n)
  24. (- (/ 1 n) (/ 1 x)))