9
$\begingroup$

I need help for a problem I m having trouble with. I need to create a list with the first 10'000 digits of Pi and sum the digits 259 to 7233.

I managed to create a list with the following code: list1 = RealDigits[Pi, 10, 10]

But then I am unable to do any computation with it.

Somebody can help me ?

Thanks !

$\endgroup$
  • $\begingroup$ Why create a list of 10000 digits when you are not going to use any digit beyoun digit 7223? $\endgroup$ – m_goldberg Feb 21 at 22:23
  • 4
    $\begingroup$ Why bother? It will be approximately equal to (7233 - 259 + 1) * (0 + 9) / 2 :-) $\endgroup$ – Selcuk Feb 22 at 0:57
  • $\begingroup$ Related: (125025) $\endgroup$ – Mr.Wizard Feb 25 at 11:04
5
$\begingroup$
RealDigits[Pi, 10, 10000] // First // Take[#, {259, 7233}] & // Total
$\endgroup$
  • $\begingroup$ Thanks it works as well! $\endgroup$ – user63037 Feb 21 at 21:03
7
$\begingroup$

Does this do what you want:

Total @ RealDigits[Pi, 10, 10^4][[1,259;;7233]]
$\endgroup$
  • $\begingroup$ Thanks a lot it works! $\endgroup$ – user63037 Feb 21 at 21:03
6
$\begingroup$

You can use the four-argument of form of RealDigits:

  • RealDigits[$x, b, len, n$] gives len digits starting with the coefficient of $b^n$.
m = 259;
n = 7233;
Total@First@RealDigits[Pi, 10, n - (m - 1), -(m - 1)]

31574

$\endgroup$
  • 3
    $\begingroup$ That should be Total @ First @ RealDigits[Pi, 10, 7233 - 259 + 1, -258] instead. $\endgroup$ – Carl Woll Feb 22 at 1:19
  • $\begingroup$ Thank you @CarlWoll. Fixed. $\endgroup$ – kglr Feb 22 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy