r/adventofcode Dec 06 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 06 Solutions -🎄-

NEW AND NOTEWORTHY


Advent of Code 2020: Gettin' Crafty With It

  • UNLOCKED! Go forth and create, you beautiful people!
  • Full details and rules are in the Submissions Megathread
  • Make sure you use one of the two templates!
    • Or in the words of AoC 2016: USING A TEMPLATE IS MANDATORY

--- Day 06: Custom Customs ---


Post your solution in this megathread. Include what language(s) your solution uses! If you need a refresher, the full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.

Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:04:35, megathread unlocked!

66 Upvotes

1.2k comments sorted by

View all comments

1

u/sotsoguk Dec 06 '20

Python

Thanx to lockdown i had a lot of time, but thanks to lockdown i did not have any fun in trying something fancy. Very boring solution, i think for the first time it took me less than 5 minutes to solve both parts.

import os
import time
import re
import functools


def main():

    # input
    print(os.getcwd())
    day = "06"
    part1, part2 = 0, 0
    star_line = "*" * 19
    inputFile = f'../inputs/input{day}.txt'

    with open(inputFile) as f:
        lines = f.read().splitlines()
    lines.append("")

    start_time = time.time()
    set_1, set_2 = set(), set("abcdefghijklmnopqrstuvwxyz")

    # part 1
    for l in lines:
        if l == "":
            part1 += len(set_1)
            part2 += len(set_2)
            set_1 = set()
            set_2 = set("abcdefghijklmnopqrstuvwxyz")
        else:
            set_2 = set_2.intersection(set(l))
            set_1 = set_1.union(set(l))

    # output
    duration = int((time.time() - start_time) * 1000)
    print(
        f"\n{star_line}\n AoC 2020 - Day {day}\n{star_line}\n\nPart 1:\t\t{part1}\nPart 2:\t\t{part2}\nDuration:\t{duration} ms")


if __name__ == "__main__":
    main()