Anonymous user
Digital root/Multiplicative digital root: Difference between revisions
Digital root/Multiplicative digital root (view source)
Revision as of 15:52, 20 November 2020
, 3 years agoUpdated to work with Nim 1.4. Removed "newSeqWith" template which is available in standard module "sequtils".
(Added a picolisp solution.) |
(Updated to work with Nim 1.4. Removed "newSeqWith" template which is available in standard module "sequtils".) |
||
Line 1,917:
=={{header|Nim}}==
{{trans|Python}}
<lang nim>import strutils,
var mdr = @[n]
while mdr[mdr.high] > 9:
Line 1,933 ⟶ 1,927:
mdr.add n
(mdr.high, mdr[mdr.high])
for n in [123321, 7739, 893, 899998]:
echo align($n, 6)," ",mdroot(n)
echo ""
var table = newSeqWith(10, newSeq[int]())
for n in 0..int.high:
if table.map((x: seq[int]) => x.len).min >= 5: break
table[mdroot(n).mdr].add n
for mp, val in table:
echo mp, ": ", val[0..4]</lang>
{{out}}
<pre>123321 (mp: 3, mdr: 8)
|