hn21b=: 3 : 0
i=. 0
m=. 2 3 5x
z=. 1x
for. i.<:y do.
 z=. z , a=. <./ m
 b=. a = m
 i=. i + b
 m=. (m*-.b) + (b*2 3 5) * i{z
end.
z
)



----- Original Message -----
From: "R.E. Boss" <[email protected]>
Date: Tuesday, January 5, 2010 21:39
Subject: Re: [Jprogramming] Rosetta code: hamming numbers
To: 'Programming forum' <[email protected]>

> See 
> http://www.jsoftware.com/jwiki/RE%20Boss/J-blog/HN for more 
> information.
> 
> R.E. Boss
> 
> 
> -----Oorspronkelijk bericht-----
> Van: [email protected]
> [mailto:[email protected]] Namens Sherlock, Ric
> Verzonden: dinsdag 5 januari 2010 22:29
> Aan: Programming forum
> Onderwerp: Re: [Jprogramming] Rosetta code: hamming numbers
> 
> Here is another idea for calculating hamming numbers
>   ([: /:~ [: ,@:(*/"0 1)/ 2 3 5x&(^"0 1)) i.40
> 
> The next step is to work out how big the integer list needs to 
> be for a
> given problem
> >:@>....@%: y  is a quick & dirty solution but seems to work.
> 
>  hamming2=:  <: { ([: /:~ [: ,@:(*/"0 1)/ 2 3 5x&(^"0
> 1))@(i.@>:@>....@%:@(>./))
>    hamming2 >:i.20
> 1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 25 27 30 32 36
>    hamming2 1691
> 2125764000
> 
> - doesn't solve the 1e6 problem though
> 
> > -----Original Message-----
> > From: [email protected] [mailto:programming-
> > [email protected]] On Behalf Of Aai
> > Sent: Wednesday, 6 January 2010 06:17
> > To: Programming forum
> > Subject: [Jprogramming] Rosetta code: hamming numbers
> > 
> > J-ers and RC-ers,
> > 
> > I entered a solution for this task:
> > http://rosettacode.org/wiki/Hamming_numbers .
> > 
> > hamming =: {. (/:~...@~.@] , 2 3 5 * {)/ @ (1x ,~ i...@-)
> > 
> > 
> > However the problem is (which I didn't realize while entering my
> > solution) producing the millionth hamming number. So if anyone 
> has a
> > better idea on this, go ahead. Of course it's also a challenge 
> to come
> > up with a very J-ish solution for this problem.
> > 
> > R.E.Boss perhaps? I used your solution HN00 and it produced 
> the answer
> > in ca. 47 sec on my computer.

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to