예제 #1
0
# Solution to https://projecteuler.net/problem=67

import utilities

triangle = []

def main():
	triangle = utilities.read_to_2d_list("euler-067-data.txt")
	for i in range(1, len(triangle)):
		for j in range(len(triangle[i])):
			max_val = 0
			if j != 0:
				max_val = triangle[i - 1][j - 1]
			if j != len(triangle[i]) - 1 and triangle[i - 1][j] > max_val:
				max_val = triangle[i - 1][j]
			triangle[i][j] += max_val
	return max(triangle[len(triangle) - 1])

if __name__ == "__main__":
	utilities.print_runtime(main)
예제 #2
0
    while groups[m] != val:
        next_m = groups[m]
        groups[m] = val
        m = next_m
    return val


def main():
    group_counts = [1] * MAX
    groups = {i: i for i in range(MAX)}
    call_index = 1
    call_count = 0
    while group_counts[find_call_group(groups, PM_NUMBER)] < MAX // 100 * 99:
        lagged_fibonacci(2)
        caller = lagged_fib_cache[call_index] % MAX
        called = lagged_fib_cache[call_index + 1] % MAX
        call_index += 2
        if caller != called:
            call_count += 1
            caller_group = find_call_group(groups, caller)
            called_group = find_call_group(groups, called)
            if caller_group != called_group:
                group_counts[caller_group] += group_counts[called_group]
                group_counts[called_group] = 0
                groups[called_group] = caller_group
    return call_count


if __name__ == "__main__":
    utils.print_runtime(main)