r/adventofcode • • Dec 04 '20

SOLUTION MEGATHREAD -🎄- 2020 Day 04 Solutions -🎄-

Advent of Code 2020: Gettin' Crafty With It


--- Day 04: Passport Processing ---


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:12:55, megathread unlocked!

90 Upvotes

1.2k comments sorted by

View all comments

2

u/Rain-Any Dec 04 '20

Saw people doing tedious manual checks for all values. sharing my py code :

with open("input.txt", "r") as file:
    credlist = file.read().split("\n\n")
for i in credlist:
    credlist = [sub.replace('\n', ' ') for sub in credlist]
x=0
for i in credlist:
    if len(i.split(" "))<7:
        x+=1
    if len(i.split(" "))>=7:
        for a in i.split(" "):
            if a.startswith("cid") and len(i.split(" "))==7:
                x+=1
print(len(credlist)-x)

0

u/[deleted] Dec 04 '20

[deleted] — view deleted comment

1

u/Rain-Any Dec 04 '20

the 7 base values dont have to be hard coded at all. some people were doing that. i used my logic here for the base classification in the second code too. but its true that the subchecks in the 2nd one have to be hardcoded. was talking about people hardcoding the 7 classes in the first part mainly.

2

u/daggerdragon Dec 04 '20

Expanding your language for folks who are Ctrl-F'ing the megathreads: Python

2

u/Rain-Any Dec 04 '20

im pretty new to py actually. im more used to c and js. using py for this aoc so that i can oearn it better