Skip to content

Instantly share code, notes, and snippets.

@carl-eastlund
Created September 2, 2013 20:12
Show Gist options
  • Select an option

  • Save carl-eastlund/6416843 to your computer and use it in GitHub Desktop.

Select an option

Save carl-eastlund/6416843 to your computer and use it in GitHub Desktop.
Attempting to reproduce a hash-iterate-key bug using hash tables directly rather than sets.
#lang racket
(require math/number-theory)
(define limit 28123)
(define (is-abundant? n)
(> (- (apply + (divisors n)) n) n))
(define abundants
(for/hash ([i (in-range limit)]
#:when (is-abundant? i))
(values i #t)))
(define abundants-gen
(for*/hash ([i (in-hash-keys abundants)]
[j (in-hash-keys abundants)]
#:when (and (not (= i j)) (< (+ i j) limit)))
(values (+ i j) #t)))
(hash-count abundants-gen)
abundants-gen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment