Category talk:Wren-i64: Difference between revisions
Content added Content deleted
(→Source code (Wren): Added largestPrime and prev{rime) |
(→Source code (Wren): Replaced U64.digitSum with a more efficient version.) |
||
Line 1,112: | Line 1,112: | ||
return 0 |
return 0 |
||
} |
} |
||
// Return a list of the current instance's base 10 digits |
|||
digits { toString.map { |d| Num.fromString(d) }.toList } |
|||
// Returns the sum of the current instance's base 10 digits. |
|||
digitSum { |
|||
digitSum { digits.reduce(0) { |acc, d| acc = acc + d } } // the sum of those digits |
|||
var sum = 0 |
|||
for (d in toString.bytes) sum = sum + d - 48 |
|||
return sum |
|||
} |
|||
} |
} |
||