Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Advent of Code 2016
#1
If someone has to much spare time before Christmas Snowman
Advent of Code 2016
Reply
#2
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))
Reply
#3
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)
Reply
#4
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())
Reply
#5
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))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Advent of code 2023 snippsat 2 790 Dec-08-2023, 06:52 PM
Last Post: snippsat
  Advent of Code 2019 ThomasL 9 5,151 Dec-15-2019, 10:54 AM
Last Post: ndc85430
  Advent of Code 2018 snippsat 0 2,595 Dec-01-2018, 11:05 PM
Last Post: snippsat
  Matching emails in outlook 2016 Erdix 7 4,082 Jan-17-2018, 09:36 AM
Last Post: Erdix
  Advent of Code 2017 stranac 5 4,789 Dec-05-2017, 08:50 AM
Last Post: buran
  Complete Python Programming Course 2016: Code using Python 3 free udemy course Yoriz 0 4,230 Oct-17-2016, 05:21 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020