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$
3
  • 1
    $\begingroup$ Why create a list of 10000 digits when you are not going to use any digit beyoun digit 7223? $\endgroup$
    – m_goldberg
    Commented Feb 21, 2019 at 22:23
  • 5
    $\begingroup$ Why bother? It will be approximately equal to (7233 - 259 + 1) * (0 + 9) / 2 :-) $\endgroup$
    – Selcuk
    Commented Feb 22, 2019 at 0:57
  • $\begingroup$ Related: (125025) $\endgroup$
    – Mr.Wizard
    Commented Feb 25, 2019 at 11:04

3 Answers 3

6
$\begingroup$
RealDigits[Pi, 10, 10000] // First // Take[#, {259, 7233}] & // Total
$\endgroup$
1
  • $\begingroup$ Thanks it works as well! $\endgroup$
    – user63037
    Commented Feb 21, 2019 at 21:03
7
$\begingroup$

Does this do what you want:

Total @ RealDigits[Pi, 10, 10^4][[1,259;;7233]]
$\endgroup$
1
  • $\begingroup$ Thanks a lot it works! $\endgroup$
    – user63037
    Commented Feb 21, 2019 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$
2
  • 3
    $\begingroup$ That should be Total @ First @ RealDigits[Pi, 10, 7233 - 259 + 1, -258] instead. $\endgroup$
    – Carl Woll
    Commented Feb 22, 2019 at 1:19
  • $\begingroup$ Thank you @CarlWoll. Fixed. $\endgroup$
    – kglr
    Commented Feb 22, 2019 at 1:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.