aUCBLogo Demos and Tests / sumnumberstest
to sumnumberstest
;by Mike Sandy
local [start t v]
make "start timemilli
make "v sum_num 5 1 1E7
make "t (timemilli-:start)
print (list "sum\ of\ digits\ = :v
"time\ = int :t/60000 "min
60 * (:t/60000-int :t/60000) "sec )
end
;to sum_digits_to_base :b :n [:res 0 ]
; if :n =0[op ifelse empty? :res [0][:res]]
; op (sum_digits_to_base :b int :n/:b (remainder :n :b)+:res)
;end
;For aUCBLogo the 2nd proc. becomes:
to sum_digits_to_base :b :n [:res 0 ]
if :n==0 [output ifelse empty? :res [0][:res]]
output (sum_digits_to_base :b int :n/:b (remainder :n :b)+:res)
end
to sum_num :b :n1 :n2 [:s 0]
if :n1 > :n2 [output :s]
output (sum_num :b :n1+1 :n2 :s+sum_digits_to_base :b :n1)
end