Advent of Code 2016 - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: Advent of Code 2016 (/thread-1099.html) |
Advent of Code 2016 - snippsat - Dec-03-2016 If someone has to much spare time before Christmas Advent of Code 2016 RE: Advent of Code 2016 - snippsat - Dec-03-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)) RE: Advent of Code 2016 - snippsat - Dec-06-2016 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) RE: Advent of Code 2016 - snippsat - Dec-06-2016 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()) RE: Advent of Code 2016 - nilamo - Dec-06-2016 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)) |