# You know what? Fuck math, unless it turns out the first solution works a lot # faster. import std/math func isArmstrongNumber(n: int): bool = var total, exponent = 0 let digits: int = n.float32.log10.ceil.int while 10 ^ exponent < n: total += (n div (10 ^ exponent) mod 10) ^ digits exponent += 1 n == total # Versus this one: import std/math import std/strutils import std/sequtils func isArmstrongNumber(n: int): bool = n == ($n).foldl(a + parseInt($b) ^ len($n), 0)