Digital root/Multiplicative digital root: Difference between revisions
Digital root/Multiplicative digital root (view source)
Revision as of 18:55, 26 June 2021
, 2 years ago→{{header|ALGOL 68}}: Revised formatting, use operators instead of procedures
(Added Quackery.) |
(→{{header|ALGOL 68}}: Revised formatting, use operators instead of procedures) |
||
Line 167:
=={{header|ALGOL 68}}==
<lang algol68>BEGIN # Multiplicative Digital Roots #
# structure to hold the results of calculating the digital root & persistence #
MODE DR = STRUCT( INT root, INT persistence );
# returns the product of the digits of number #
OP DIGITPRODUCT = ( INT number )INT:
BEGIN
INT result := 1;
WHILE result TIMESAB ( rest MOD 10 );
rest OVERAB 10;
END; # DIGITPRODUCT #
# calculates the multiplicative digital root and persistence of number #
OP MDROOT = ( INT number
BEGIN
END; # MDROOT #
# prints a number and its MDR and MP #
PROC print md root = ( INT number )VOID:
BEGIN
print( ( whole( number, -6 ), ": MDR: ", whole( root OF mdr, 0 ), ", MP: ", whole( persistence OF mdr, -2 ), newline ) )
END; # print md root #
# prints the first few numbers with each possible Multiplicative Digital #
# Root. The number of values to print is specified as a parameter #
PROC tabulate mdr = ( INT number of values )VOID:
[ 0 : 9, 1 : number of values ]INT mdr values;
[ 0 : 9 ]INT mdr counts;
mdr counts[ AT 1 ] := ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
# find the first few numbers with each possible mdr #
INT values found := 0;
INT required values := 10 * number of values;
FOR value FROM 0 WHILE values found < required values DO
DR mdr = MDROOT value;
# need more values with this multiplicative digital root #
mdr values[ root OF mdr, mdr counts[ root OF mdr ] ] := value
print( ( "MDR: [n0..n" + whole( number of values - 1, 0 ) + "]", newline ) );
print( ( "=== ========", newline ) );
STRING separator := ": [";
print( ( whole( mdr pos, -3 ) ) );
FOR val pos FROM 2 LWB mdr values TO 2 UPB mdr values DO
print( ( "]", newline ) )
OD
END; # tabulate mdr #
print md root( 123321 );
print md root( 7739 );
Line 269 ⟶ 236:
print md root( 899998 );
tabulate mdr( 5 )
{{out}}
<pre>
|