def main(): inp = load_file('inputs/p081.in') inp = [list(map(int, line.split(','))) for line in inp.splitlines()] score = djikstra(inp) print(score) print('CORRECT ANSWER:', score == 427337)
def main(): inp = load_file('inputs/p022.in') names = list(map(lambda x: x[1:-1], inp.split(','))) total = 0 for i, name in enumerate(sorted(names)): total += score(name) * (i + 1) print(total)
def main(): inp = load_file('inputs/p042.in') inp = [i[1:-1] for i in inp.split(',')] counter = 0 for w in inp: if istriword(w): counter += 1 print(counter)
def main(): inp = load_file('inputs/p099.in') inp = [tuple(map(int, line.split(','))) for line in inp.splitlines()] best = (0, 0) for i, (base, exp) in enumerate(inp): num = logpower(base, exp) if num > best[1]: best = (i + 1, num) print(best[0])
def test(): from time import sleep inp = load_file('inputs/p059.in') inp = [int(d) for d in inp.split(',')] keys = ['god'] # 25% error check. for key in keys: dec = decrypt(inp, ordseq(key)) print(''.join(chrseq(dec))) print('=== {}: {} ==='.format(key, sum(dec))) sleep(2)
def main(): inp = load_file('inputs/p059.in') inp = [int(d) for d in inp.split(',')] wordlist = load_file('inputs/dict.in') wordlist = set(wordlist.splitlines() + ['i', 'a']) keys = perm([i for i in range(97, 122 + 1)], 3) error = 0.25 possible = [] for key in keys: dec = decrypt(inp, key) dec = ''.join(chrseq(dec)).split() counter = 0 for word in dec: if word.lower() not in wordlist: counter += 1 if counter > len(dec) * error: break else: possible.append((''.join(chrseq(key)), counter / len(dec))) print([s[0] for s in sorted(possible, key=lambda x: x[1])])
def main(): inp = load_file('inputs/p345.in').splitlines() inp = [list(map(int, re.sub('\s+', ' ', line).split())) for line in inp] m = Matrix(inp)