7
$\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 !

New contributor
Nico is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
  • 3
    $\begingroup$ "But then I am unable to do any computation with it." - is your keyboard plugged in? $\endgroup$ – Kuba 9 hours ago
  • $\begingroup$ Why create a list of 10000 digits when you are not going to use any digit beyoun digit 7223? $\endgroup$ – m_goldberg 8 hours ago
  • 2
    $\begingroup$ Why bother? It will be approximately equal to (7233 - 259 + 1) * (0 + 9) / 2 :-) $\endgroup$ – Selcuk 5 hours ago
2
$\begingroup$
RealDigits[Pi, 10, 10000] // First // Take[#, {259, 7233}] & // Total
$\endgroup$
  • $\begingroup$ Thanks it works as well! $\endgroup$ – Nico 9 hours ago
3
$\begingroup$

Does this do what you want:

Total @ RealDigits[Pi, 10, 10^4][[1,259;;7233]]
$\endgroup$
  • $\begingroup$ I think this is a good start, but omits the requirement to sum the digits 259 to 7233. Oh, and now someone else has posted an answer which covers that too. $\endgroup$ – High Performance Mark 9 hours ago
  • $\begingroup$ Thanks a lot it works! $\endgroup$ – Nico 9 hours ago
3
$\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 5 hours ago
  • $\begingroup$ Thank you @CarlWoll. Fixed. $\endgroup$ – kglr 4 hours ago

Your Answer

Nico is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.