def main(): ''' Driver function ''' total = 0 for puzzle in load_puzzles(src_file('e096')): solved = solve(puzzle) total += int(solved['A1'] + solved['A2'] + solved['A3']) print(total)
def main(): ''' Driver functions ''' anagrams = get_anagrams(src_file('e098')) max_length = len(max(anagrams, key=lambda i: len(i[0]))[0]) sqrs, sqr_set = squares_by_length(max_length) max_sqr = 0 for a in anagrams: for w1, w2 in permutations(a, 2): for s in sqrs[len(a[0])]: valid = True vals = dict() nums = set() for i, c in enumerate(w1): if (s[i] in nums and (c not in vals or s[i] != vals[c])) or ( c in vals and s[i] != vals[c]): valid = False break nums.add(s[i]) vals[c] = s[i] if valid: new = ''.join(vals[c] for c in w2) if new in sqr_set: max_sqr = max(max(max_sqr, int(new)), int(s)) print(max_sqr)
def main(): ''' Driver function ''' data = open(src_file('e011')) grid = load_grid(data) maximum = max([max_across(grid), max_across(np.rot90(grid)), max_diag(grid), max_diag(np.fliplr(grid))]) print(maximum)
def main(): ''' Driver function ''' seqs = read_file(src_file('e185')) poss = poss_digits(seqs) def search(result, index): for val in seqs.values(): if not (0 <= val <= (16 - index)): return None if index == 16: for val in seqs.values(): if val != 0: return None return result for p in poss[index]: found = [] for key in seqs.keys(): if key[index] == p: found += [key] seqs[key] -= 1 ans = search(result + [p], index + 1) if ans: return ans for key in found: seqs[key] += 1 print(''.join(str(n) for n in search([], 0)))
def main(): ''' Apply sum_tri to triangle until only one row remains ''' src_file_path = src_file('e067') with open(src_file_path) as infile: triangle = [list(map(int, line.split())) for line in infile] for _ in range(file_length(src_file_path) - 1): triangle = sum_tri(triangle) print(triangle[0][0])
def main(): ''' Driver function ''' pairs = load_data(src_file('e099')) cur_max = pairs[0] for p in pairs[1:]: exp = log(cur_max[0], p[0]) if p[1] // exp >= cur_max[1]: cur_max = p print(pairs.index(cur_max) + 1)
def main(): ''' Driver function ''' matrix = load_matrix(src_file('e107')) init_weight = sum( sum(n for n in row if n != float("inf")) for row in matrix) // 2 min_matrix = minimize_matrix(matrix) min_weight = sum( sum(n for n in row if n != float("inf")) for row in min_matrix) // 2 print(init_weight - min_weight)
def main(): ''' Driver function ''' words = list(csv.reader(open(src_file('e042'))))[0] count = 0 for word in words: value = word_value(word) if is_tri(value): count += 1 print(count)
def main(): ''' Driver function ''' count = 0 for line in open(src_file('e054')): p1 = line[0:14].split() p2 = line[15:29].split() if hand_rank(p1) > hand_rank(p2): count += 1 print(count)
def main(): ''' Driver function ''' total = 0 with open(src_file('e089')) as data: for line in data: old_numeral = line.strip() num = roman_to_int(old_numeral) new_numeral = int_to_roman(num) total += len(old_numeral) - len(new_numeral) print(total)
def main(): ''' Driver function ''' triangles = load_triangles(src_file('e102')) print(sum(origin_in(t) for t in triangles))
def main(): ''' Sums the numbers and finds the first 10 digits ''' with open(src_file('e013')) as data: num = sum(int(line.strip()) for line in data) print(str(num)[:10])
def main(): ''' Driver function ''' graph, matrix = build_graph(src_file('e081')) print(dijkstra(graph, (0, 0), (79, 79)) + int(matrix[0][0]))
def main(): ''' Driver function ''' encrypted = [int(n) for n in open(src_file('e059')).read().split(',')] decrypted = test_keys(encrypted) print(sum([ord(c) for c in decrypted]))