Advertisement
danchaofan

Euler #99

Dec 12th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. line, best, bestline, bestrightmost = 0, 0, 0, 0
  2. for a in list(open("expos.txt")):
  3.     line += 1
  4.     print(line)
  5.     a = a.rstrip()
  6.     temp, nums, product, digits, rightmost = "", [], 1, 0, 0
  7.     for b in a:
  8.         if b == ",":
  9.             nums.append(int(temp))
  10.             temp = ""
  11.             continue
  12.         temp += b
  13.     nums.append(int(temp))
  14.     for c in range(nums[1]):
  15.         product *= nums[0]
  16.         rightmost = int(str(product)[0])
  17.         if len(str(product)) > 8:
  18.             digits += len(str(product)) - 8
  19.             product = int(str(product)[:8])
  20.     if digits > best:
  21.         best = digits
  22.         bestline = line
  23.     if digits == best:
  24.         if rightmost > bestrightmost:
  25.             best = digits
  26.             bestline = line
  27.             bestleftmost = rightmost
  28. print(bestline)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement