Hide this comment

Since checking if number belongs to Hamming class is particular case of integer factorization problem then most trivial approach would be to try recursively factorize that number. For example - Hamming number test until 500-th integer

1
2
3
4
5
6
7
8
let rec IsHammingNumber n d = 
    match (n,d) with
    | (1,_) -> true
    | (_,_) when d > 5 -> false
    | (_,_) -> match (n % d = 0) with
               | true ->  IsHammingNumber (n/d) d
               | false -> IsHammingNumber n (d+1)  in
                        [for x in 1..500 do if IsHammingNumber x 2 then yield x] |> printfn "%A"

But that may be in-efficient, just a jump start on problem...

By on 12/17/2010 11:26 AM ()Reply
Hide this comment

Use the LazyList type from the F# PowerPack; here is a thread about the answer:

[link:cs.hubfs.net]

By on 11/3/2010 8:08 AM ()Reply
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper

Logging in...