Largest number divisible by its digits: Difference between revisions

Content added Content deleted
(Check if first digit is even.)
m (Modified comment.)
Line 1,114: Line 1,114:


===Base 10===
===Base 10===
Brute-force with some optimizations: there is no 5 and the first digit (rightmost) must be even. We use also an iterator rather than a conversion to string, which speeds up significantly the computation. Result is obtained in about 800 ms.
Derived from C++ version, with some more optimizations: we check that the first digit (rightmost) is even and we use also an iterator rather than a conversion to string, which speeds up significantly the computation. Result is obtained in about 800 ms.
<lang nim>iterator digits(n: int): int =
<lang nim>iterator digits(n: int): int =
var n = n
var n = n