# Running this through benchy: import std/math import std/strutils import std/sequtils func isArmstrongNumber1(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 func isArmstrongNumber2(n: int): bool = n == ($n).foldl(a + parseInt($b) ^ len($n), 0) import benchy timeIt("numbers only"): var total = 0 for i in 1..10_000: if i.isArmstrongNumber1: inc total timeIt("via string"): var total = 0 for i in 1..10_000: if i.isArmstrongNumber2: inc total