>From RE Boss's blog 
http://www.jsoftware.com/jwiki/RE%20Boss/J-blog/HN
 
and this essay

http://www.jsoftware.com/jwiki/Essays/Hamming%20Number

There are a few approaches mentioned to either directly get the ith hamming 
number or generate the list.





an issue with nh (super fast) is that it is innacurate.)

  nh 1001 
52428800
  {:  hn21b 1002 NB. Roger's version
52428800

Another function approach that is very fast, and doesn't limit it to the 
hamming factors 2 3 5 is to get a list of hamming numbers below a threshold:

X =: 1 : 'm&{::@:['
H =: (0 X ([: ~. ] #~ >:) 1 X (] , [: , */) ])(^:_)&1

  # H 52428800 ; 2 3 5 
1002

  {: /:~ H 52428800 ; 2 3 5 
52428800 


Can also apply to aribtrary prime list (Roger's function is also easily 
modified to do this)
  # H 52428800 ; 2 3 5 7 11 13 
13102 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to