Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Hamming-numbers/REXX/hamming-numbers-1.rexx
Normal file
20
Task/Hamming-numbers/REXX/hamming-numbers-1.rexx
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/*REXX program computes Hamming numbers: 1 ──► 20, # 1691, and the one millionth. */
|
||||
numeric digits 100 /*ensure enough decimal digits. */
|
||||
call hamming 1, 20 /*show the 1st ──► twentieth Hamming #s*/
|
||||
call hamming 1691 /*show the 1,691st Hamming number. */
|
||||
call hamming 1000000 /*show the 1 millionth Hamming number.*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
hamming: procedure; parse arg x,y; if y=='' then y= x; w= length(y)
|
||||
#2= 1; #3= 1; #5= 1; @.= 0; @.1= 1
|
||||
do n=2 for y-1
|
||||
@.n= min(2*@.#2, 3*@.#3, 5*@.#5) /*pick the minimum of 3 Hamming numbers*/
|
||||
if 2*@.#2 == @.n then #2= #2 + 1 /*number already defined? Use next #. */
|
||||
if 3*@.#3 == @.n then #3= #3 + 1 /* " " " " " " */
|
||||
if 5*@.#5 == @.n then #5= #5 + 1 /* " " " " " " */
|
||||
end /*n*/ /* [↑] maybe assign next 3 Hamming#s. */
|
||||
do j=x to y; say 'Hamming('right(j, w)") =" @.j
|
||||
end /*j*/
|
||||
|
||||
say right( 'length of last Hamming number =' length(@.y), 70); say
|
||||
return
|
||||
26
Task/Hamming-numbers/REXX/hamming-numbers-2.rexx
Normal file
26
Task/Hamming-numbers/REXX/hamming-numbers-2.rexx
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*REXX program computes Hamming numbers: 1 ──► 20, # 1691, and the one millionth.*/
|
||||
call hamming 1, 20 /*show the 1st ──► twentieth Hamming #s*/
|
||||
call hamming 1691 /*show the 1,691st Hamming number. */
|
||||
call hamming 1000000 /*show the 1 millionth Hamming number.*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
hamming: procedure; arg x,y; if y=='' then y= x; w= length(y); L= length(y-1); p= 2**L
|
||||
numeric digits max(9, p + p%4 + p%16) /*ensure enough decimal digits. */
|
||||
#2= 1; #3= 1; #5= 1; @.= 0; @.1= 1
|
||||
do n=2 for y-1
|
||||
_2= @.#2 + @.#2 /*this is faster than: @.#2 * 2 */
|
||||
_3= @.#3 + @.#3 + @.#3 /* " " " " @,#3 * 3 */
|
||||
_5= @.#5 * 5
|
||||
m= _2 /*assume a minimum (of the 3 Hammings).*/
|
||||
if _3 < m then m= _3 /*is this number less than the minimum?*/
|
||||
if _5 < m then m= _5 /* " " " " " " " */
|
||||
@.n= m /*now, assign the next Hamming number.*/
|
||||
if _2 == m then #2= #2 + 1 /*number already defined? Use next #.*/
|
||||
if _3 == m then #3= #3 + 1 /* " " " " " " */
|
||||
if _5 == m then #5= #5 + 1 /* " " " " " " */
|
||||
end /*n*/ /* [↑] maybe assign next Hamming #'s. */
|
||||
do j=x to y; say 'Hamming('right(j, w)") =" @.j
|
||||
end /*j*/
|
||||
|
||||
say right( 'length of last Hamming number =' length(@.y), 70); say
|
||||
return
|
||||
26
Task/Hamming-numbers/REXX/hamming-numbers-3.rexx
Normal file
26
Task/Hamming-numbers/REXX/hamming-numbers-3.rexx
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*REXX program computes Hamming numbers: 1 ──► 20, # 1691, and the one millionth.*/
|
||||
call hamming 1, 20 /*show the 1st ──► twentieth Hamming #s*/
|
||||
call hamming 1691 /*show the 1,691st Hamming number. */
|
||||
call hamming 1000000 /*show the 1 millionth Hamming number.*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
hamming: procedure; arg x,y; if y=='' then y= x; w= length(y); L= length(y-1); p= 2**L
|
||||
numeric digits max(9, p + p%4 + p%16) /*ensure enough decimal digits. */
|
||||
#2= 1; #3= 1; #5= 1; @.= 0; @.1= 1
|
||||
do n=2 for y-1
|
||||
_2= @.#2 + @.#2 /*this is faster than: @.#2 * 2 */
|
||||
_3= @.#3 + @.#3 + @.#3 /* " " " " @,#3 * 3 */
|
||||
_5= @.#5 * 5
|
||||
m= _2 /*assume a minimum (of the 3 Hammings).*/
|
||||
if _3 < m then m= _3 /*is this number less than the minimum?*/
|
||||
if _5 < m then m= _5 /* " " " " " " " */
|
||||
@.n= format(m,,,,0) /*now, assign the next Hamming number.*/
|
||||
if _2 == m then #2= #2 + 1 /*number already defined? Use next #.*/
|
||||
if _3 == m then #3= #3 + 1 /* " " " " " " */
|
||||
if _5 == m then #5= #5 + 1 /* " " " " " " */
|
||||
end /*n*/ /* [↑] maybe assign next Hamming #'s. */
|
||||
do j=x to y; say 'Hamming('right(j, w)") =" @.j / 1
|
||||
end /*j*/
|
||||
|
||||
say right( 'length of last Hamming number =' length(@.y / 1), 70); say
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue