Task

Take a   Natural Number   in a given base and return the sum of its digits:

   110         sums to   1
   123410   sums to   10
   fe16       sums to   29
   f0e16     sums to   29


class SumDigits {
  function : Main(args : String[]) ~ Nil {
    SumDigit(1)->PrintLine();
    SumDigit(12345)->PrintLine();
    SumDigit(0xfe, 16)->PrintLine();
    SumDigit(0xf0e, 16)->PrintLine();
  }
 
  function : SumDigit(value : Int, base : Int := 10) ~ Int {
    sum := 0;
    do {
      sum += value % base;
      value /= base;
    }
    while(value <> 0);
    return sum;
  }
}
 