Project Euler - Problem 13


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/usr/bin/python
  2.  
  3. # Project Euler - Problem 13
  4. print "\nProject Euler - Problem 13"
  5. print "Find the first ten digits of the sum"
  6. print "of a set of one-hundred 50-digit numbers."
  7.  
  8. # Read in first 50-digit number
  9.  
  10. f = open('problem13.num', 'r')
  11.  
  12. x = [None]*50
  13. p = [None]*100
  14. sum = 0
  15.  
  16. for n in range(0,100):
  17. for i in range(0,50):
  18. x[i] = (f.read(1))
  19. if (x[i] == '\n'):
  20. x[i] = f.read(1)
  21. s = ''.join(map(str, x))
  22. sum += int(s)
  23. print sum

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.