Python Forum

Full Version: Advent of Code 2016
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
If someone has to much spare time before Christmas Snowman
Advent of Code 2016
Mine for Advent of Code day 3:
sides = [list(map(int, line.split())) for line in open("input.txt")]
print([sum(i) > 2 * max(i) for i in sides].count(True))
There are some fun and original task in Advent of Code.
Mine for day 5:
import hashlib

def hash_find():
    hash_lst = []
    i = 0
    while len(hash_lst) < 8:
        make = 'cxdnnyjw{}'.format(i)
        i += 1
        if hashlib.md5(str.encode(make)).hexdigest().startswith('00000'):
            hash_lst.append(hashlib.md5(str.encode(make)).hexdigest())
    return(hash_lst)

def password(hash_find):
    print(''.join(i[5] for i in hash_find()))

if __name__ == '__main__':
    password(hash_find)
Mine for Advent of Code day 6:
from collections import Counter

def adv_6():
   with open('input_adv_6.txt') as f:
       data = [i.strip() for i in f]
       lenght_x = len(data[0])
       rows = [[i[c] for i in data] for c in range(lenght_x)]
       return ''.join([Counter(i).most_common(1)[0][0] for i in rows])

if __name__ == '__main__':
   print(adv_6())
I also used Counter for #6:
import collections

columns = []

with open("input.txt") as fin:
    for line in fin:
        for ndx, ch in enumerate(line):
            if ndx >= len(columns):
                columns.append([])
            columns[ndx].append(ch)

answer = [collections.Counter(col).most_common(1)[0][0] for col in columns]
print(''.join(answer))