advent_of_code_2021

My attempts to work through the 2021 Advent of Code problems.
git clone https://git.eamoncaddigan.net/advent_of_code_2021.git
Log | Files | Refs | README | LICENSE

commit 2a907e61f669b35fe9260f01175bc8e4b8ed8c46
parent 1382a599ad70cc4124cc5c7946c6ff39d5bd0556
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date:   Wed,  8 Dec 2021 11:12:22 -0500

Just comments, prepared to solve the puzzle soon

Diffstat:
Aday08_part1.py | 46++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+), 0 deletions(-)

diff --git a/day08_part1.py b/day08_part1.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +"""Advent of Code 2021, day 8 (part 1): decode the scrambled seven-segment +displays""" + +# This is a fun puzzle. I sat down with pen and paper and proved to myself that +# you can deduce the mapping from scrambled segments to the full set of digits +# using just the information provided. It looks like this: +# * If 2 segments are lit, that's '1' +# * If 3 segments are lit, that's '7' +# * If 4 segments are lit, that's '4' +# * If 7 segments are lit, that's '8' +# (So far, this was given in the puzzle prompt, nothing new yet) +# * If 5 segments are lit, it's '2', '3', or '5' +# * If 6 segments are lit, it's '0', '6', or '9' +# (Okay, that's not useful... yet) +# * If 5 segments are lit and they include all the segments in '7', that's '3' +# * If 6 segments are lit and they don't include all the segments in '7', +# that's '6' +# * If 6 segments are lit and they include the union of the segments comprising +# '3' and '4', that's '9' +# * If 6 segments are lit and it's not a '6' or '9', that's '0' +# * If 5 segments are lit and it is missing only one of the segments from '6', +# that's '2' +# * If 5 segments are lit and it's not a '2' or a '3', that's '5' +# So right now in part 1, it's possible to find the four digits displayed for +# each line of puzzle input! But... +# I'm not going to implement it yet, because "good programmers are lazy", and +# maybe part 2 will throw me for a loop? Regardless, figuring this out has +# influenced my decision about how to represent the data; i.e., we're doing a +# lot of set operations, so I'm going to use sets for everything, and since +# it's easy to imagine wanting to use these sets of lit segments as dictionary +# keys, we'll use immutable `frozenset`s specifically (which can be `dict` +# keys). + +EXAMPLE_INPUT = \ +"""be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe +edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc +fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg +fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb +aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea +fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb +dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe +bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef +egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb +gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce +"""