Digital root/Multiplicative digital root: Difference between revisions

Moved 3 redirect entries here (to correct the task counts)
m (→‎{{header|Free Pascal}}: first occurence of persistence 0..11 .Inline GetMulDigits)
(Moved 3 redirect entries here (to correct the task counts))
Line 27:
</pre>
Show all output on this page.
 
;Similar:
The Product of decimal digits of n page was redirected here, and had the following description<br>
Find the product of the decimal digits of a positive integer &nbsp; '''n''', &nbsp; where '''n <= 100'''
The three existing entries for Phix, REXX, and Ring have been moved here, under <nowiki>===Similar===</nowiki> headings, feel free to match or ignore them.
 
 
Line 2,376 ⟶ 2,381:
9 9 19 33 91 119
</pre>
 
===Similar===
<!--<lang Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">pdd</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%2d"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">product</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sq_sub</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">),</span><span style="color: #008000;">'0'</span><span style="color: #0000FF;">)))</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Product of the decimal digits of 1..100:\n%s\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">100</span><span style="color: #0000FF;">),</span><span style="color: #000000;">pdd</span><span style="color: #0000FF;">),</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)})</span>
<!--</lang>-->
{{out}}
<pre>
Product of the decimal digits of 1..100:
1 2 3 4 5 6 7 8 9 0
1 2 3 4 5 6 7 8 9 0
2 4 6 8 10 12 14 16 18 0
3 6 9 12 15 18 21 24 27 0
4 8 12 16 20 24 28 32 36 0
5 10 15 20 25 30 35 40 45 0
6 12 18 24 30 36 42 48 54 0
7 14 21 28 35 42 49 56 63 0
8 16 24 32 40 48 56 64 72 0
9 18 27 36 45 54 63 72 81 0
</pre>
 
 
=={{header|PL/I}}==
Line 2,854 ⟶ 2,881:
9: [9 19 33 91 119 133 191 313 331 911 1119 1133 1191 1313 1331 1911 3113 3131 3311 9111 11119 11133 11191 11313 11331 11911 13113 13131 13311 19111 31113 31131 31311 33111]
═══ ═════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
</pre>
 
===Similar===
<lang rexx>/*REXX pgm finds positive integers when shown in hex that can't be written with dec digs*/
parse arg n cols . /*obtain optional argument from the CL.*/
if n=='' | n=="," then n = 100 /*Not specified? Then use the default.*/
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
w= 10 /*width of a number in any column. */
title= ' the product of the decimal digits of N, where N < ' n
say ' index │'center(title, 1 + cols*(w+1) ) /*display the title for the output. */
say '───────┼'center("" , 1 + cols*(w+1), '─') /* " a sep " " " */
$=; idx= 1 /*list of products (so far); IDX=index.*/
do #=1 for n; L= length(#) /*find products of the dec. digs of J. */
p= left(#, 1) /*use first digit as the product so far*/
do j=2 for L-1 until p==0 /*add an optimization when product is 0*/
p= p * substr(#, j, 1) /*multiply the product by the next dig.*/
end /*j*/
$= $ right(p, w) /*add the product ───► the $ list. */
if #//cols \== 0 then iterate /*have we populated a line of output? */
say center(idx, 7)'│' substr($, 2); $= /*display what we have so far (cols). */
idx= idx + cols /*bump the index count for the output*/
end /*#*/ /*stick a fork in it, we're all done. */
 
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
say '───────┴'center("" , 1 + cols*(w+1), '─') /*display the foot sep for output. */</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
index │ the product of the decimal digits of N, where N < 100
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ 1 2 3 4 5 6 7 8 9 0
11 │ 1 2 3 4 5 6 7 8 9 0
21 │ 2 4 6 8 10 12 14 16 18 0
31 │ 3 6 9 12 15 18 21 24 27 0
41 │ 4 8 12 16 20 24 28 32 36 0
51 │ 5 10 15 20 25 30 35 40 45 0
61 │ 6 12 18 24 30 36 42 48 54 0
71 │ 7 14 21 28 35 42 49 56 63 0
81 │ 8 16 24 32 40 48 56 64 72 0
91 │ 9 18 27 36 45 54 63 72 81 0
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────
</pre>
 
Line 2,938 ⟶ 3,005:
8 => 8 18 24 29 36
9 => 9 19 33 91 119
</pre>
 
===Similar===
<lang ring>
load "stdlib.ring"
see "working..." + nl
see "Product of decimal digits of n:" + nl
 
row = 0
limit = 100
 
for n = 1 to limit
prod = 1
strn = string(n)
for m = 1 to len(strn)
prod = prod * number(strn[m])
next
see "" + prod + " "
row = row + 1
if row%5 = 0
see nl
ok
next
 
see "done..." + nl
</lang>
{{out}}
<pre>
working...
Product of decimal digits of n:
1 2 3 4 5
6 7 8 9 0
1 2 3 4 5
6 7 8 9 0
2 4 6 8 10
12 14 16 18 0
3 6 9 12 15
18 21 24 27 0
4 8 12 16 20
24 28 32 36 0
5 10 15 20 25
30 35 40 45 0
6 12 18 24 30
36 42 48 54 0
7 14 21 28 35
42 49 56 63 0
8 16 24 32 40
48 56 64 72 0
9 18 27 36 45
54 63 72 81 0
done...
</pre>
 
7,794

edits