"Rory Winston" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > (If you're wondering, this is a Project Euler question :)) > > If I wanted to calculate the sum of the digits in the decimal > representation > of 2^1000, what would be a good way to go about that?
Try this: > library(gmp) > for (N in c(10,16,32,100,1000)) + { + s <- as.character(pow.bigz(2,N)) + t <- as.numeric(unlist(strsplit(s,""))) + cat(N, s, sum(t), "\n") + } 10 1024 7 16 65536 25 32 4294967296 58 100 1267650600228229401496703205376 115 1000 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376 1366 The first few can be verified manually. -- efg Earl F. Glynn Bioinformatics Stowers Institute for Medical Research ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.