p075.scm 1.0 KB

123456789101112131415161718192021222324252627
  1. ;; Singular integer right triangles
  2. ;; Well we could simply enumerate a^2 + b^2, check to see if that is a perfect square...
  3. ;; Okay, we will go through all a and b's recording each value in a hashtable.
  4. ;; If value doesn't exits, add it and set to true, otherwise set to false.
  5. ;; The issue with this is that we may get some false positives if we don't ensure that a^2 + b^2 = c^2
  6. ;; does not work to simpliy loop through a and b
  7. ;; How can we know when this works... well c must be greater than a + b and if c must be an integer, then, it must be the case that a and b are integers... and that there sqrt-sum must be an integer... so we are dealing with perfect squares,
  8. ;; Well it seems that we can do some kind of sieve...
  9. ;; How about some kind of binary search?
  10. (define-module (unsolved p075))
  11. (define (calc-test range)
  12. (do [(i 0 (1+ i))]
  13. [(> i (/ range 3))]
  14. (do [(j 0 (1+ j))]
  15. [(> j i)]
  16. (* i j))))
  17. (define (singular-right-triangles range)
  18. (define triangle-map (make-hash-table range))
  19. 0)