Hamming numbers are numbers of the form  

    H = 2i × 3j × 5k
           where 
     i,  j,  k  ≥  0 

Hamming numbers   are also known as   ugly numbers   and also   5-smooth numbers   (numbers whose prime divisors are less or equal to 5).



Task

Generate the sequence of Hamming numbers, in increasing order.   In particular:

 Show the   first twenty   Hamming numbers.
 Show the   1691st   Hamming number (the last one below   231).
 Show the   one millionth   Hamming number (if the language – or a convenient library – supports arbitrary-precision integers).


Related tasks

 Humble numbers
 N-smooth numbers


References

 Wikipedia entry:   Hamming numbers     (this link is re-directed to   Regular number).
 Wikipedia entry:   Smooth number
 OEIS entry:   A051037   5-smooth   or   Hamming numbers
 Hamming problem from Dr. Dobb's CodeTalk (dead link as of Sep 2011; parts of the thread here and here).


define hamming use $limit
    [ ] as $h
    1 $h 0 set
    2 as $x2   3 as $x3    5 as $x5
    0 as $i    0 as $j     0 as $k
    1 $limit 1 + 1 range each as $n
        $x3 $x5 min $x2 min    $h $n   set
        $h $n get   $x2 =  if
            $i  1 +   as $i
            $h $i get    2 *     as $x2
        $h $n get   $x3 =  if
            $j  1 +   as $j
            $h $j get    3 *     as $x3
        $h $n get   $x5 =  if
            $k  1 +   as $k
            $h $k get    5 *     as $x5
    $h   $limit 1 -   get
 
1 21 1 range each as $lim
    $lim hamming print " " print
"\n" print
 
"Hamming(1691) is: " print    1691 hamming print    "\n" print
 
# Raven can't handle > 2^31 using integers
#
#"Hamming(1000000) is: " print   1000000 hamming print    "\n" print