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


 
/* REXX ************************************************************** 
* 04.12.2012 Walter Pachl                                               
**********************************************************************/ 
digits='0123456789ABCDEF'                                               
Do i=1 To length(digits)                                                
  d=substr(digits,i,1)                                                  
  value.d=i-1                                                           
  End                                                                   
Call test '1'                                                           
Call test '1234'                                                        
Call test 'FE'                                                          
Call test 'F0E'                                                         
Exit                                                                    
test:                                                                   
  Parse Arg number                                                      
  res=right(number,4)                                                   
  dsum=0                                                                
  Do While number<>''                                                   
    Parse Var number d +1 number                                        
    dsum=dsum+value.d                                                   
    End                                                                 
  Say res '->' right(dsum,2)                                            
  Return