Skip to content

Instantly share code, notes, and snippets.

@robot-dreams
Last active January 15, 2017 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robot-dreams/b6e5043e2abae13530e9029684b5b2c7 to your computer and use it in GitHub Desktop.
Save robot-dreams/b6e5043e2abae13530e9029684b5b2c7 to your computer and use it in GitHub Desktop.
Hamming's problem (enumerate all positive integers divisible by no primes other than 2, 3, or 5)
hamming :: [Integer]
hamming =
1 : merge3
(map (*2) hamming)
(map (*3) hamming)
(map (*5) hamming)
where
merge (x:xs) (y:ys) =
case compare x y of
LT -> x : merge xs (y:ys)
EQ -> x : merge xs ys
GT -> y : merge (x:xs) ys
merge3 xs ys zs =
merge xs (merge ys zs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment