Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. from itertools import islice
  2.  
  3. with open('pi-hex.1000000.txt', 'r') as f:
  4.     pi = (int(i, 16) for i in f.read())
  5.  
  6.  
  7. ndigits = int('31415', 16)
  8. result = sum(i for i in islice(pi, ndigits) if i % 2 == 1)
  9.  
  10. print(f'Sum of first {hex(ndigits)}={ndigits} digits of pi (in hex) = {hex(result)}={result}.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement