Digital root: Difference between revisions

Content added Content deleted
Line 560: Line 560:
=={{header|Eiffel}}==
=={{header|Eiffel}}==
<lang Eiffel>
<lang Eiffel>
class
APPLICATION

inherit
ARGUMENTS

create
make

feature {NONE} -- Initialization

digital_root_test_values: ARRAY [INTEGER_64]
-- Test values.
once
Result := <<627615, 39390, 588225, 393900588225>> -- base 10
end

digital_root_expected_result: ARRAY [INTEGER_64]
-- Expected result values.
once
Result := <<9, 6, 3, 9>> -- base 10
end


make
local
results: ARRAY [INTEGER_64]
i: INTEGER
do
from
i := 1
until
i > digital_root_test_values.count
loop
results := compute_digital_root (digital_root_test_values [i], 10)
if results [2] ~ digital_root_expected_result [i] then
print ("%N" + digital_root_test_values [i].out + " has additive persistence " + results [1].out + " and digital root " + results [2].out)
else
print ("Error in the calculation of the digital root of " + digital_root_test_values [i].out + ". Expected value: " + digital_root_expected_result [i].out + ", produced value: " + results [2].out)
end
i := i + 1
end
end


compute_digital_root (a_number: INTEGER_64; a_base: INTEGER): ARRAY [INTEGER_64]
compute_digital_root (a_number: INTEGER_64; a_base: INTEGER): ARRAY [INTEGER_64]