# A replacement for IntegerDigits: computing Sloane OEIS A229024 sequence

GROUPS:
 Hans Havermann 1 Vote I am on a quest to determine the 13th term in Sloane's (OEIS) A229024, a sequence that I recently authored. This sequence is all about calculating Total[IntegerDigits[n!] for a reasonably large subset of contiguous n. For the 13th term, n is in the vicinity of 182623000, the factorial of which has more than 1.4*10^9 decimal digits. It takes some 20 minutes for Mathematica to return on my system the sum of the digits of one such n!, so it will take me many months to chart the roughly 15000 sums that I think need to be done. Unfortunately, I am finding that for a random, roughly-2% of the n that I try, Mathematica returns an erroneous result. For example, I get for Total[IntegerDigits[182616009!]] a value of 1600311191. I know that this sum is incorrect because it is not evenly divisible by 9. (It is also significantly smaller than the sum of digits for nearby n-factorial. It appears that IntegerDigits[182616009!] introduces more than a billion additional trailing zeros preceding the 45653996 trailing zeros that I expect.)  I've reported the bug to Wolfram in the hope that this will be fixed in some future version, assuming of course that it is not my system that is responsible. So what procedure can I use to get a correct value for Total[IntegerDigits[182616009!]] in the interim? I thought to use DigitCount[182616009!] but Total[RotateRight[DigitCount[182616009!]]*Range[0, 9]] results in the identical incorrect value as before.
2 years ago
8 Replies
 Ilian Gachevski 3 Votes Which version were you using and on what platform? With version 9.0.1, I getIn[1]:= Total[IntegerDigits[182616009!]]Out[1]= 6226582986 The number of trailing zeros is as expected: In[2]:= IntegerExponent[182616009!]Out[2]= 45653996In[3]:= Length[Last[Split[IntegerDigits[182616009!]]]]Out[3]= 45653996
2 years ago
 Hans Havermann 1 Vote I am using 9.0.1 as well, on a current generation iMac (OS 10.8.5) with 32GB RAM (which is the maximum possible). Just doing IntegerDigits consumes most of that RAM (I do have other stuff running in the background). The fact that you would consider doing a Split on top of that suggests that you have at least twice as much RAM and points to the likelihood that my sporadic IntegerDigits misbehavior is the result of a system memory constraint.
2 years ago
 Simon Schmidt 1 Vote Iliang: What is your $MaxNumber?182616009! (* Overflow[] *)$MaxNumber  (* 1.233433712981650*10^323228458 *)
2 years ago
 Ilian Gachevski 2 Votes Thank you for the information, today I have been able to reproduce this problem on a couple of OS X machines, and will contact the appropriate developers. Your feedback is much appreciated. For a possible workaround in the meantime, perhaps you could try one of the approaches mentioned in this Mathematica SE thread, although I am afraid they are more likely to exhaust the available memory (yes, I did not worry much about Split, but that's only because the Linux server I used had 144 GB of RAM).@Simon: There is a bit more headroom on a 64-bit machine. On my Linux box, \$MaxNumber is 8.768126706828697*10^2711437152599256