Jump to content

Digital root/Multiplicative digital root: Difference between revisions

m
→‎{{header|REXX}}: re-did the output.
m (→‎{{header|REXX}}: modified the MDR subroutine to accept negative numbers as well.)
m (→‎{{header|REXX}}: re-did the output.)
Line 584:
say '═══ ' copies("═",10+(target+2)**2%2)
 
do k=0 for 10; hits=0; _= /*show #'s that have an MDR of K.*/
do m=0 until hits==target /*find five #'s with an MDR of K.*/
?=right(m,1) /*obtain right-most digit of M. */
if k\==0 then if ?==0 then iterate
select
when k==3 | k==5 | k==7 | k==9 then nop
when k==3 then if ?\==1 & ?\==3 then iterate
when k==5 then if ?//2==0 then iterate
when k==7 then if ?\==1 & ?\==7 then iterate
when k==9 then if ?\==1 & ?\==3 & ?\==9 then iterate
whenotherwise k==1 then m=copies(1,hits+1) nop
otherwise if word(mdr(m),2)\==k then iterate
end /*select*/
if k==1 then m=copies(1,hits+1)
otherwise else if word(mdr(m),2)\==k then iterate
hits=hits+1; _=space(_ m',') /*yes, we got a hit, add to list.*/
end /*m*/ /* [↑] built a list of MDRs = k */
Line 623 ⟶ 624:
1: [1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111, 11111111111, 111111111111, 1111111111111, 11111111111111, 111111111111111, 1111111111111111, 11111111111111111, 111111111111111111, 1111111111111111111, 11111111111111111111]
2: [2, 12, 21, 26, 34, 37, 43, 62, 73, 112, 121, 126, 134, 137, 143, 162, 173, 211, 216, 223]
3: [13, 313, 1131, 13113, 21131, 23311, 311113, 331131, 411311, 433111, 5111113, 5311131, 6111311, 6313111, 7131111, 73111113, 81111131, 83111311, 91113111, 93131111]
4: [4, 14, 22, 27, 39, 41, 72, 89, 93, 98, 114, 122, 127, 139, 141, 172, 189, 193, 198, 212]
5: [15, 315, 535, 751, 953, 1157, 1375, 15115, 17135, 19151, 21153, 23157, 25175, 27315, 29351, 31355, 33359, 35395, 37511, 39513]
6: [6, 16, 23, 28, 32, 44, 47, 48, 61, 68, 74, 82, 84, 86, 116, 123, 128, 132, 144, 147]
7: [17, 717, 1171, 17117, 21171, 27711, 311117, 371171, 411711, 477111, 5111117, 5711171, 6111711, 6717111, 7171111, 77111117, 81111171, 87111711, 91117111, 97171111]
8: [8, 18, 24, 29, 36, 38, 42, 46, 49, 63, 64, 66, 67, 76, 77, 79, 81, 83, 88, 92]
9: [19, 319, 933, 1191, 13119, 19133, 21191, 23313, 29331, 31911, 331119, 391133, 411191, 431313, 491331, 511911, 533113, 593131, 613311, 639111]
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.