Last active
January 15, 2017 05:46
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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