Well I was unable to post my last answer to a similar question because is was tagged as duplicate because of this question.

So now, on to this question. I still think it best to traverse across an ordered set so as not to have to compensate for not.

I did find my no2s3s5s function useful for this, too. It is funny that no2s3s5s starts from 11. no2s3s5s is just counting in a particular way.

This is no2s3s5s

no2s3s5s = scanl (\b a -> a + b) 11 $ cycle [2,4,2,4,6,2,6,4]

It produces mostly primes, from 11 to 97 there is only 49, 77 and 91 that are not prime, the dreaded 7s. It is used in hamseq in lieu of primes. My bad.

hamseq n = [ b | b <- [1..n], all (>0) [mod b f | f <- take (div b 2) (7:no2s3s5s)]]

hamseq 729

produces [1,2,3,4,5,6,8,9,10,12,15,16,18,20,24,25,27,30,32,36,40,45,48,50,54,60,64,72,75,80,81,90,96,100,108,120,125,128,135,144,150,160,162,180,192,200,216,225,240,243,250,256,270,288,300,320,324,360,375,384,400,405,432,450,480,486,500,512,540,576,600,625,640,648,675,720,729]

@Will Ness, I am literal minded. I never thought about producing this list with parameter 77. My bad.

But, here

hamseq n = take n $ [ b | b <- [1..], all (>0) [mod b f | f <- take (div b 2) (7:no2s3s5s)]]

12/2/2018 Well again because of the Fundamental Theorem of Arithmetic (my original motivation for this function) I stopped using no2s3s5 in hamseq . There are many fewer values in a primes list. I have a really fast prime function but I have to dig it up. I did this one just earlier today. The hamseq function is way faster, now, not linear but faster.

prs n =takeWhile (<n)$[p|p <-no2s3s5s, all (>0) [mod p f|f <- take (ceiling.sqrt.fromIntegral$p) (2:3:5:7:no2s3s5s)]] hamseq' n ls = [ b | b <- [1..n], all (>0) [mod b f | f <- take (div b 3) ls]] hamseq n = hamseq' n (7:(prs n))

The (div b 3) is approximate. The optimum number is between 3 and 4. I'll find my way faster prime generator and replace this clunker.

I forgot this and it cuts the last time in half.

base n = 1:[ d | d <- [2..n], any (==0) $ [mod d f | f <- [2,3,5]]] so hamseq' n ls = [ b | b <- (base n), all (>0) [mod b f | f <- take (div b 3) ls]]

12/4/2018

Well, i gave up. It is just not possible to use a prime list to factor each x because the length of the list becomes to very large and contributes to lethargy.

The alternative is to successively factor each number by one of [2,3,5]. This means the last value calculated is used in the next calculations, that is recursive. Simple recursion in Haskell means fold/scan .

First is the divuntil (divide until) for the scanl in facs . It repeatedly divided a value by one of [2,3,5], whichever matches before and after each divide. This was split into two functions but now is merged and is faster.

Second is the facs function which uses scanl to generate quotients to re-divide. The irritating nature of div causes scanl to drill down to 1 for Hamming numbers. If the quotient does not result in 1 then the number is not Hamming. If the quotient does not divide by 2,3 or 5 the result is the null list. Finally an unnamed list comprehension to run facs repeatedly on a list of numbers. A list comprehension because it would otherwise require an if with no else , that is, no easy way to ignore or discard values.

divuntil = \b a -> let ff=[f | f <- [2,3,5], mod b f == 0] in if null ff then 0 else div b (ff !! 0) facs=

-> last.takeWhile (>0) $ scanl divuntil n [1..] take 200 $ [ b | b <- [1..], facs b == 1]

This code is ugly, I know. It can most certainly be improved upon. Probably because of the way I write Haskell. One line-at-a-time. My bad. I could probable break down and put this into a file of one function which would probably speed it up, too.

The speed up over my last function is well over 12 times I estimate. It's still not close to linear but faster.

facs can be used with any value to identify it as Hamming or not.

I start this with what I thought was an answer to another question, that is, all the multiples of [2,3,5]. I answered with this.

base = scanl (\b a -> a+b) 2 $ cycle [1,1,1,1,2,1,1,2,2,1,1,2,2,1,1,2,1,1,1,1,2,2]

It produces the multiples a sample of which is above. The recursive addition is again, counting. It is faster than recursive division of a single value. It makes the following faster.

take 600 $ [ b | b <- base, facs b == 1]

A take 600 is 18.84 seconds with [1..] on my office PC and 16.28 seconds with base .

Faster is more fun. Try

take 430 $ [ floor.log.fromIntegral $ b | b <- scbase, facs b == 1]

You'll can get counts of how many of each of [0..12] which are [1,4,8,10,14,21,27,34,44,51,59,72,82] and the deltas [1,3,4, 2,4,7, 6,7,10, 7,8,13, 10]

12/10/2018 As I suspected, one function is faster than many. The scanl is not so controllable. The div function can also be controlled. This function will analyze one number and issue a True (Hamming) or False (not Hamming). It is run in a list comprehension as the list comprehension can produce ans x based on a Boolean.

fac n | n < 7 = True | even n = fac (div n 2) | mod n 3 == 0 = fac (div n 3) | mod n 5 == 0 = fac (div n 5) | otherwise = False

take 600 $ [ d | d <- base, fac d ] 9.57 seconds is the best I can do by checking each value. Next, if I have time, a more analytical approach.

12/21/2018

The speed-up is 10 fold from fac just above this but this is way more the test of a concept.

This is three functions. The first is b25 which replaces base from above. b25 produces all evens and 5s (mod 10).

b25 = scanl' (\b a -> (b+a)) 2 $ cycle [2,1,1,2,2,2]

What is interesting to me is the main function produces no 3-multiples.

Multiples of 3 are provided by the second function.

the3s =

-> scanl' (\b a -> a*b) 1 $ replicate n 3

The fac2 function changes to process only evens or odds (5s).

In it n > 7 is superfluous. Maybe a case statement.

fac2 n | n <= 7 = True | n > 7 = if even n then fac (div n 2) else fac (div n 5) | otherwise = False

Run this like,

sort $ the3s 14 ++ [ d | d <- (take 150000 b25), fac2 d]

The speedup is about 10 fold. 600 Hammings took .92 of a second in GHCi.

I've gotten much use from fac above because you can add things to the list comprehension.

Indeed, processing 150,000 numbers to get 600 is crazy and the best way to get anywhere close to linear is to not process from a list.