princeofsudan

Project Euler#40 Champernowne's constant

Mar 7th, 2013
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. #An irrational decimal fraction is created by concatenating the positive integers:
  2.  
  3. #0.123456789101112131415161718192021...
  4.  
  5. #It can be seen that the 12th digit of the fractional part is 1.
  6.  
  7. #If dn represents the nth digit of the fractional part, find the value of the following expression.
  8.  
  9. #d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000
  10.  
  11. digit = '.'
  12. i = 1
  13.  
  14. #Create a string one million digits long by concatenating the counting numbers starting from 1.
  15. while len(digit)<= 1000000:
  16.     digit += str(i)
  17.     i += 1
  18.  
  19. #multiply together the single digits at the positions specified above.
  20. j = 1
  21. count = 1
  22. for k in range(7):
  23.     count *= int(digit[j])
  24.     j *= 10
  25. print count
Advertisement
Add Comment
Please, Sign In to add comment