p046.scm 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. ;; Goldenbachs other conjecture
  2. ;; TODO: it would be nice to not have to guess how many primes i need using erato
  3. ;; I can verify when the value is no longer considered when either the prime or the double is larger than it
  4. (define-module (solved p046))
  5. (use-modules (euler primes)
  6. (srfi srfi-1)
  7. (ice-9 control))
  8. ;; Returns value which disproves goldenbach's conjecture
  9. (define (disprove-conjecture)
  10. (let*
  11. ([n (expt 10 4)]
  12. [prime-bitvector (erato-bit n)]
  13. [prime-lst (prime-bitvector->lst prime-bitvector)]
  14. [twice-square-lst (map (lambda (val) (* 2 (expt val 2)))
  15. (iota n 1))])
  16. (let lp ([primes prime-lst] [twice-sqr-lst twice-square-lst])
  17. (cond
  18. [(null? primes) #f]
  19. [(null? twice-sqr-lst)
  20. (lp (cdr primes) twice-square-lst)]
  21. [else
  22. (when (<= (+ (car primes) (car twice-sqr-lst)) n)
  23. (bitvector-set! prime-bitvector
  24. (+ (car primes) (car twice-sqr-lst))
  25. #t))
  26. (lp primes (cdr twice-sqr-lst))]))
  27. (let answer-lp ([i 3])
  28. (cond
  29. [(> i n) "not enough primes"]
  30. [(bitvector-ref prime-bitvector i) (answer-lp (+ 2 i))]
  31. [else i]))))