コード例 #1
0
It turns out that the conjecture was false.

What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?'''

from Functions import import_csv
import time

def get_twice_squares_ls(limit):
    ls =  []
    for i in range(1, limit):
        ls.append(2* i**2)
    return ls

start_time = time.clock
primes_ls = import_csv('primes_1e6.csv')
primes_ls = list(map(int, primes_ls))
twice_squares_ls = get_twice_squares_ls(1000)
ls_of_odds = []
last_composite = 9
print(twice_squares_ls)
input()

for composite in range(1, 1000000, 2):
    if composite in primes_ls:
        continue

    for prime in primes_ls:
        if prime > composite:
            continue
コード例 #2
0
7 4
2 4 6
8 5 9 3

That is, 3 + 7 + 4 + 9 = 23.

Find the maximum total from top to bottom in triangle.txt (right click and 'Save Link/Target As...'),
a 15K text file containing a triangle with one-hundred rows.

NOTE: This is a much more difficult version of Problem 18. It is not possible to try every route to solve this problem,
as there are 299 altogether! If you could check one trillion (1012) routes every second it would take over
twenty billion years to check them all. There is an efficient algorithm to solve it. ;o)"""

from Functions import import_csv, runtime
import time

start_time = time.clock()
file = import_csv("triangle.csv")
for row in file:
    for i in range(len(row)):
        row[i] = int(row[i])

sum = 0
for row in file:
    print(max(row))
    input()
    sum += max(row)

print(sum)
runtime(start_time)