Categories

## My solution to Advent of Code 2020’s Day 7 challenge, in Python

Welcome to another installment in my Advent of Code 2020 series, where I present my solutions to this year’s Advent of Code challenges!

In this installment, I share my Python solution to Day 7 of Advent of Code, titled Handy Haversacks.

## The Day 7 challenge, part one

### The challenge

Here’s the text from part one of the challenge:

You land at the regional airport in time for your next flight. In fact, it looks like you’ll even have time to grab some food: all flights are currently delayed due to issues in luggage processing.

Due to recent aviation regulations, many rules (your puzzle input) are being enforced about bags and their contents; bags must be color-coded and must contain specific quantities of other color-coded bags. Apparently, nobody responsible for these regulations considered how long they would take to enforce!

For example, consider the following rules:

These rules specify the required contents for 9 bag types. In this example, every `faded blue` bag is empty, every `vibrant plum` bag contains 11 bags (5 `faded blue` and 6 `dotted black`), and so on.

You have a `shiny gold` bag. If you wanted to carry it in at least one other bag, how many different bag colors would be valid for the outermost bag? (In other words: how many colors can, eventually, contain at least one `shiny gold` bag?)

In the above rules, the following options would be available to you:

• `bright white` bag, which can hold your `shiny gold` bag directly.
• `muted yellow` bag, which can hold your `shiny gold` bag directly, plus some other bags.
• `dark orange` bag, which can hold `bright white` and `muted yellow` bags, either of which could then hold your `shiny gold` bag.
• `light red` bag, which can hold `bright white` and `muted yellow` bags, either of which could then hold your `shiny gold` bag.

So, in this example, the number of bag colors that can eventually contain at least one `shiny gold` bag is `4`.

How many bag colors can eventually contain at least one `shiny gold` bag? (The list of rules is quite long; make sure you get all of it.)

Please be warned: If you want to try solving the challenge on your own and without any help, stop reading now! The remainder of this post will be all about my solution to both parts of the Day 7 challenge.

### Importing the data

Every Advent of Code participant gets their own set of data. I copied my data and went through my usual process of bringing it into a Jupyter Notebook running a Python kernel.

This involves pasting it into a triple-quoted string and then using Python’s `splitlines()` method to break it up into a list of strings. The result is `main_raw_input`:

### Creating the data structure

I feel that I can never stress this enough: A key part of coming up with solutions to Advent of Code challenges is to come up with good structures for the input data.

Here’s my function that takes the initial, somewhat-massaged input data, currently living in `main_raw_input`, and turns it into a data structure that I could do some problem-solving with:

The `create_data_structure()` function creates a table that makes it easy to look up a given bag and see what bags it contains.

It takes each line in the input, which follows this general form:

[adjective and color] bags contain [one or more of

It first makes use of this regular expression…

…to separate the line into two parts:

• The containing bag, which is captured by the `(\w+ \w+)` group, and
• The contained bag(s), which are captured by the `(.*)` group.

The contained bag(s) are further parsed using this regular expression…

…to create a list of tuples of the form:

Here’s how I used `create_data_structure()` to create the data structure:

Here’s a sample of the what the structure looked like for my data:

With the data structure built, it was now possible to write a function to determine how many shiny gold bags a given bag would contain:

It’s the return of our friend:

This function checks the contents of the given bag. If there are bags in the given bag, it checks the contents of those bags and counts the shiny gold ones. If there are bags in those bags, it checks the contents of those bags and counts the shiny gold ones. And so on…

Now that I had the `shiny_gold_bag_count()` function, I could write another function — `bags_containing_at_least_one_shiny_gold_bag()` — that would apply the `shiny_gold_bag_count()` function to all the bags in the collection, giving me the answer to the part one:

In my case, the count was 326.

## The Day 7 challenge, part two

### The challenge

Here’s the text of part two:

It’s getting pretty expensive to fly these days – not because of ticket prices, but because of the ridiculous number of bags you need to buy!

Consider again your `shiny gold` bag and the rules from the above example:

• `faded blue` bags contain `0` other bags.
• `dotted black` bags contain `0` other bags.
• `vibrant plum` bags contain `11` other bags: 5 `faded blue` bags and 6 `dotted black` bags.
• `dark olive` bags contain `7` other bags: 3 `faded blue` bags and 4 `dotted black` bags.

So, a single `shiny gold` bag must contain 1 `dark olive` bag (and the 7 bags within it) plus 2 `vibrant plum` bags (and the 11 bags within each of those): `1 + 1*7 + 2 + 2*11` = `32` bags!

Of course, the actual rules have a small chance of going several levels deeper than this example; be sure to count all of the bags, even if the nesting becomes topologically impractical!

Here’s another example:

In this example, a single `shiny gold` bag must contain `126` other bags.

How many individual bags are required inside your single `shiny gold` bag?

My solution was the following function:

Once again, my solution was a recursive one. This function checks the contents of the given bag. If there are bags in the given bag, it counts them and then checks their contents. If there are bags in those bags, it counts them and checks their contents. And so on…

Getting the solution was a matter of calling the function:

And for my data, the answer was 5635.

Categories

## Meet the Auth0 DevRel Team — Monday, December 14 at noon Eastern / 9:00 a.m. Pacific

Here’s your chance to get to know the Auth0 Developer Relations teamthey’re holding an online meet-and-greet this Monday, December 14th at noon Eastern / 9:00 a.m. Pacific!

You can catch it on Twitch.

Here’s the description of the event:

Dev Rel, Developer Relations, Developer Advocacy, Developer avocado… What does it all mean? In this episode you will have the chance to connect and ask your questions about all of this to the very own Auth0 Dev Rel team. Maybe you just want to know what we do, or how we got here. Maybe you want to learn how to get into Dev Rel. Or maybe you just want to meet us and say hi! Whatever your reason, don’t miss this episode where we will also be hosting a secret santa live! Why? Well, that way you can also get to know us better by seeing what we would buy each other this season.

Here’s who you’ll meet…

### James Quick, Senior Developer Advocate

James is a developer, speaker, and teacher with a passion for web development, design, and developer tools. He is a Senior Developer Advocate at Auth0 and has over 7 years of experience in Advocacy and Software Development. In his spare time, he runs a YouTube channel, plays co-ed soccer with his wife, spends time with his dogs, and can solve a Rubik’s cube in under two minutes.

### Sam Bellen, Senior Developer Advocate

I’m a Google Developer Expert who works as a Senior Developer Advocate Engineer at Auth0. At Auth0 we’re trying to make authentication and identification as easy as possible, while still keeping it secure. After office hours I like to play around with the web-audio API, and other “exotic” browser APIs. One of my side projects is a library to add audio effects to an audio input using JavaScript.

### Ana Cidre, Senior Developer Advocate

Ana is a Developer Advocate at Auth0. She has a degree in Fine Arts and a Master in International Business Economics and Management, so she is not your usual software developer. She loves to code and she especially likes Angular. As a very active member of the community, she regularly organises meetups and conferences, like the amazing ngSpain. In Spain, where she’s currently based, she’s an organiser of GDG Vigo and the founder of GalsTech, a group for women in tech from Galicia. Because she is so passionate about diversity, she is also a Women Techmaker Ambassador.

### Sam Julien, Senior Developer Advocate

Sam Julien is a Sr. Developer Advocate Engineer at Auth0 and a Google Developer Expert for Angular and Web Technologies. He’s also an instructor for egghead and the author of Getting Started in Developer Relations and the Developer Microskills newsletter. His favorite thing in the world is sitting outside drinking good scotch next to a fire he built himself. You can find more of Sam’s work at samjulien.com.

### Tyler Clark, Senior Developer Advocate

Tyler is a developer advocate engineer at Auth0, an egghead.io instructor, and a conference speaker. He’s worked primarily as a software engineer for the past seven years and loves getting his hands-on coding projects. His passion is in the frontend, but he also enjoys working on backend tasks. If he’s not in his office working, he’s either with his family or out playing some kind of sport.

### Kristy Gutierrez, Project Management Consultant

Kristy is a Project Manager at Auth0. New to working in the tech world, Kristy’s background is rooted in outdoor education and international adventure travel. While working at Auth0 may sound like an odd fit at first, Kristy thrives on managing complex logistics, organizing information, and solving problems. She finds the behind-the-scenes work of building more efficient processes for things like our ambassador program and events very familiar turf. When she’s not tidying up her to-do list, she loves to cook, kayak, and mountain bike.

Once again, you can catch the Auth0 Developer Relations meet-and-greet on Twitch.

### This is just one of many Avocado Labs productions!

This meet-and-greet is just one production of Avocado Labs, and I’ll let them describe themselves in their own words:

Avocado Labs is a platform where we share expert content about web technologies. Our first approach is through online meetups. We will be hosting bi-weekly meetups which consist of two talks per meetup and each edition will be focussed on one technology. Our first episode was about Angular and more specifically Ivy, the Angular compiler. We had two incredible speakers who are renowned specialists in their fields and Google Developer Experts for Angular: Manfred Steyer and Martina Kraus.

In the future, we want to explore other ways of delivering content and figure out what the community is hungry for! We also want to bring communities closer together and find ways of doing it virtually! If you have any suggestions, please feel free to reach out to us on Twitter.

This question is probably the most important. At Auth0, one of our core values is that “We give a sh^* t” and we really do! The technological community is important to us and we know that it isn’t always easy to go to a conference or a meetup, no matter what the reason might be. We believe that anyone and everyone should be able to have access to quality content and to be able to be part of a community.

We also know that right now the majority of the world is on lockdown which means that people cannot go to physical events, speakers cannot deliver amazing content, and communities cannot gather. We want to help in these times by providing at least some of this. But like mentioned above, this is an ongoing initiative. We won’t stop once things go back to “normal” – Whatever that new normal might be.

#### So, What Now?

Why not join us? To follow up on what we’re up to, you can follow us on Twitter. If you’re interested in attending our online events, we suggest that you join our meetup group. And if you would like to speak at one of our events, please fill out our call for papers. Also, any suggestions are more than welcome! Just send us a direct message on Twitter.

Categories

## What’s happening in the Tampa Bay tech/entrepreneur/nerd scene (Week of Monday, December 14, 2020)

Once again, here’s the weekly list of events for events for Tampa Bay techies, entrepreneurs, and nerds. Every week, on GlobalNerdy.com and on the mailing list, I scour the announcements for events that are interesting to or useful for those of you who are building the future here in “The Other Bay Area, on The Other West Coast”.

This list covers events from Monday, December 14 through Sunday, December 20, 2020.

Events — especially virtual, online ones — can pop up at the last minute. I add them to the list as I find out about them. Come back and check this article from time to time, as you might find a new listing that wasn’t there before!

## Do you have any events or announcements that you’d like to see on this list?

Let me know at joey@joeydevilla.com!

## Join the mailing list!

If you’d like to get this list in your email inbox every week, enter your email address below. You’ll only be emailed once a week, and the email will contain this list, plus links to any interesting news, upcoming events, and tech articles.

Join the Tampa Bay Tech Events list and always be informed of what’s coming up in Tampa Bay!

Categories

## My solution to Advent of Code 2020’s Day 6 challenge, in Python

Welcome to another installment in my Advent of Code 2020 series, where I present my solutions to this year’s Advent of Code challenges!

In this installment, I share my Python solution to Day 6 of Advent of Code, titled Custom Customs.

Please be warned: If you want to try solving the challenge on your own and without any help, stop reading now! The remainder of this post will be all about my solution to both parts of the Day 6 challenge.

## The Day 6 challenge, part one

### The challenge

Here’s the text from part one of the challenge:

As your flight approaches the regional airport where you’ll switch to a much larger plane, customs declaration forms are distributed to the passengers.

The form asks a series of 26 yes-or-no questions marked `a` through `z`. All you need to do is identify the questions for which anyone in your group answers “yes”. Since your group is just you, this doesn’t take very long.

However, the person sitting next to you seems to be experiencing a language barrier and asks if you can help. For each of the people in their group, you write down the questions for which they answer “yes”, one per line. For example:

In this group, there are `6` questions to which anyone answered “yes”: `a``b``c``x``y`, and `z`. (Duplicate answers to the same question don’t count extra; each question counts at most once.)

Another group asks for your help, then another, and eventually you’ve collected answers from every group on the plane (your puzzle input). Each group’s answers are separated by a blank line, and within each group, each person’s answers are on a single line. For example:

This list represents answers from five groups:

• The first group contains one person who answered “yes” to `3` questions: `a``b`, and `c`.
• The second group contains three people; combined, they answered “yes” to `3` questions: `a``b`, and `c`.
• The third group contains two people; combined, they answered “yes” to `3` questions: `a``b`, and `c`.
• The fourth group contains four people; combined, they answered “yes” to only `1` question, `a`.
• The last group contains one person who answered “yes” to only `1` question, `b`.

In this example, the sum of these counts is `3 + 3 + 3 + 1 + 1` = `11`.

For each group, count the number of questions to which anyone answered “yes”. What is the sum of those counts?

### Importing the data

Every Advent of Code participant gets their own set of data. I copied my data and went through my usual process of bringing it into a Jupyter Notebook running a Python kernel.

This involves pasting it into a triple-quoted string and assigning it to the variable `raw_input`, and then splitting it using two newline characters in a row as a delimiter, producing a list named `split_input`:

Each item in the `split_input` list represents the collected answers for a group. If a group has more than one person in it, a newline character separates each person’s answers.

In the sample of `split_input` shown below:

• The first line shows the answers for the first group, which is made up of two people.
• The fifth line shows the answers for the fifth group, which is made up of five people. All of them answered yes to only one question: Question v.

Finally, I split each item in `split_items`, using the newline character as the separator:

The result was a list that I named `groups`, where:

• Each item in `groups` represents a group of passengers
• Each group is a list, where each item in the list represents the answers for one passenger in that group.

Here’s a sample of `groups`:

With the input data massaged into something that could easily be processed in Python, it was time to get to work.

### Strategy

The goal was to get the total of all the “yes” answers for all the groups, keeping in mind that if any person in the group answers “yes” to a given question, the group is considered to have answered “yes” to that question.

Consider a group of three people. If:

• the first person in the group answered “yes” to questions a, b, and c,
• the second person in the group answered “yes” to questions d, e, and f,
• and the third person in the group answered “yes” to questions g, h, and i…

…the the group is considered to have answered yes to questions a though i.

To put it mathematically, a group’s answers was the union of the answers of everyone in the group.

With that in mind, I wrote this function:

This function takes advantage of the fact that while Python’s `union()` is a `set` method, it can take one or more non-`set` arguments, as long as it can convert the arguments into a set.

For example, this code:

results in this set:

I rearranged the set so that its items would appear in alphabetical order so that it would be easier to read. This is fine, because with sets, there is no order.

Now that I had `count_union_group_answers()`, I could apply it to `groups`

…and get the answer for part one: 6504.

## The Day 6 challenge, part two

### The challenge

Here’s the text of part two:

As you finish the last group’s customs declaration, you notice that you misread one word in the instructions:

You don’t need to identify the questions to which anyone answered “yes”; you need to identify the questions to which everyone answered “yes”!

Using the same example as above:

This list represents answers from five groups:

• In the first group, everyone (all 1 person) answered “yes” to `3` questions: `a``b`, and `c`.
• In the second group, there is no question to which everyone answered “yes”.
• In the third group, everyone answered yes to only `1` question, `a`. Since some people did not answer “yes” to `b` or `c`, they don’t count.
• In the fourth group, everyone answered yes to only `1` question, `a`.
• In the fifth group, everyone (all 1 person) answered “yes” to `1` question, `b`.

In this example, the sum of these counts is `3 + 0 + 1 + 1 + 1` = `6`.

For each group, count the number of questions to which everyone answered “yes”. What is the sum of those counts?

### Strategy

This time, the goal was to get the total of all the “yes” answers for all the groups, keeping in mind that the group is only considered to have answered “yes” to a given question if every person in the group answered “yes” to that question.

Consider a group of three people. If:

• the first person in the group answered “yes” to questions a, b, and c,
• the second person in the group answered “yes” to questions a, e, and f,
• and the third person in the group answered “yes” to questions a, h, and i…

…the the group is considered to have answered yes to question a, and nothing else.

To put it mathematically, a group’s answers was the intersection of the answers of everyone in the group.

All I had to do was tweak the `count_union_group_answers()` function from part one to find the intersection of group members’ answers…

…and then apply `count_intersection_group_answers()` to `groups`

This gave me the answer for part two: 3351.

Categories

## The Undercroft and their cybersecurity course, UC Baseline

One of the silver linings of my job evaporating due to the pandemic is that I suddenly had a lot of free time to try some new things. The best of those new things by far was my five weeks in The Undercroft’s inaugural UC Baseline cybersecurity course.

## What is The Undercroft?

The Undercroft was recently featured in the Tampa Magazine article, The Latest on Tampa’s Tech Scene. Here’s the relevant excerpt:

Over the past year, a number of notable out-of-state tech companies have chosen to open offices in or relocate to Tampa. Last December, Tampa beat out other up-and-coming tech hubs like Denver and Atlanta as the new home of Boston-based Drift, a marketing technology platform. Information technology training franchiser New Horizons moved its headquarters from Pennsylvania to Tampa in January. And that same month, D.C.-based technology company TheIncLab expanded to Ybor City. TheIncLab opened an “Artificial Intelligence Experience Lab” in The Undercroft, a cybersecurity incubator that launched last summer with the hopes of turning the historic Ybor into a tech industry hotspot.

“At The Undercroft, we’re focusing on the supply side of cybersecurity,” says CEO Adam Sheffield. “How do we support more talent in this community and more people who have passion for the field?”

Initially conceived as a co-working type space where startups and members could connect, The Undercroft launched a training program, UC Baseline, in response to layoffs during the coronavirus shutdown. The UC Baseline program is designed to help educate people moving into the cybersecurity workforce or transitioning from traditional IT roles. Ten participants have signed up for the six-week program that offers courses in networking, software, and hardware, according to Sheffield Incubators and accelerators are behind much of Tampa’s recent tech growth, as nonprofits like the Tampa Bay Wave and Embarc Collective offer resources and networking opportunities for local startups, including two recent programs that focus on boosting the  representation of women and diversity in the tech industry.

To describe The Undercroft as Tampa Bay’s security guild and cybersecurity coworking space is fair, but that description doesn’t capture the spirit of the place.

A better way to paint the picture would be to call it the 21st-century cybersecurity counterpart of coffeehouses in 17th- and 18th-century England. Like those coffeehouses of old, The Undercroft is a place in a beautiful old building that functions as the home for the (often boisterous) exchange of ideas, the advancement of specialized fields of knowledge, a little deal-making, and if you pay attention, a great place to learn.

(Thankfully, The Undercroft departs from those old coffeehouses in one important way: Women are welcome in The Undercroft.)

## How I ended up in UC Baseline

Back in mid-July, I’d heard about scholarships for The Undercoft’s then-upcoming cybersecurity class. I posted an article about it, which ended with this quip:

(I’ll admit it: Although I’m not likely to qualify, I applied.)

I applied, and to my surprise, I qualified, which meant that I was in this classroom a couple of weeks later:

## What I did in UC Baseline

And thus began five intense weeks, which comprised the following…

Hardware 101 — Gain a thorough understanding about the devices on which all our software runs and through which all our information flows:

Networking 101 — Learn how our systems are connected and the ways in which they communicate through these connections:

Linux 101 — Covers the foundations of security in Linux environments, the OS on which the internet runs:

Windows 101 — Here’s a big challenge — learn the foundations of security for Windows environments:

Information Security 101 — Covers everything from core IT concepts, to cybersecurity principles, methods, and practices:

Python 101 — If you’re doing security, you should have some coding skills to automate your work and build tooling, and Python’s an excellent language for that task:

This is not for someone who’s casually curious about cybersecurity. It’s a lot of work. As I wrote midway through the course:

If you take The Undercroft’s five-week cybersecurity course, UC Baseline, you will have to absorb a lot of material.

After one particular day, I felt like the cat in this video:

The course was taught by a team of instructors who work in the security industry when they’re not teaching. They’re also a personable bunch, and all of them went above and beyond in their efforts to ensure that we students were getting the most out of our classes.

## The payoff

Did it pay off to devote 5 weeks, 5 days a week, 8 hours a day, to attend UC Baseline? I think it did.

I’m really a programmer and developer evangelist by training and experience. There’s a tendency in both these lines of work to think of security as an afterthought. Attending UC Baseline, learning from actual security professionals, getting my hands on the actual hardware and software used by the pros, and even just being in The Undercroft helped me refine my security mindset.

That in turn helped me bring my A-game when it was time to apply for a job at Auth0 and then go through their rigorous interview process (which I wrote about here).

I’m not alone — 8 out of 10 of the inaugural UC Baseline class got work around a month or so after completing the program.

My thanks to the instructors for the excellent courses:  , Koby Bryan , Michael Dorsey , George Bilbrey , Jon B , Zoran Jovic, as well as my fellow students, who made the classes more enjoyable: Hawley , Danielle True ,  , Melissa Bloomer , Alyssa Kennedy , Nicolas Claude , Ryan Butler, and Anthony Davis!

And of course, special thanks to Team Undercroft, for making such a special place — the Tampa tech scene just wouldn’t be same without you: Joy Randels, Adam Sheffield, and Chris Machowski!

## Another UC Baseline in 2021!

If UC Baseline sounds interesting to you, and if you think you’re up to the challenge, there’s another one taking place in early 2021. Visit the UC Baseline page to find out more!

Categories

## My solution to Advent of Code 2020’s Day 5 challenge, in Python

Welcome to another installment in my Advent of Code 2020 series, where I present my solutions to this year’s Advent of Code challenges!

In this installment, I share my Python solution to Day 5 of Advent of Code, titled Binary Boarding.

Please be warned: If you want to try solving the challenge on your own and without any help, stop reading now! The remainder of this post will be all about my solution to both parts of the Day 5 challenge.

## The Day 5 challenge, part one

### The challenge

Here’s the text from part one of the challenge:

You board your plane only to discover a new problem: you dropped your boarding pass! You aren’t sure which seat is yours, and all of the flight attendants are busy with the flood of people that suddenly made it through passport control.

You write a quick program to use your phone’s camera to scan all of the nearby boarding passes (your puzzle input); perhaps you can find your seat through process of elimination.

Instead of zones or groups, this airline uses binary space partitioning to seat people. A seat might be specified like `FBFBBFFRLR`, where `F` means “front”, `B` means “back”, `L` means “left”, and `R` means “right”.

The first 7 characters will either be `F` or `B`; these specify exactly one of the 128 rows on the plane (numbered `0` through `127`). Each letter tells you which half of a region the given seat is in. Start with the whole list of rows; the first letter indicates whether the seat is in the front (`0` through `63`) or the back (`64` through `127`). The next letter indicates which half of that region the seat is in, and so on until you’re left with exactly one row.

For example, consider just the first seven characters of `FBFBBFFRLR`:

• Start by considering the whole range, rows `0` through `127`.
• `F` means to take the lower half, keeping rows `0` through `63`.
• `B` means to take the upper half, keeping rows `32` through `63`.
• `F` means to take the lower half, keeping rows `32` through `47`.
• `B` means to take the upper half, keeping rows `40` through `47`.
• `B` keeps rows `44` through `47`.
• `F` keeps rows `44` through `45`.
• The final `F` keeps the lower of the two, row `44`.

The last three characters will be either `L` or `R`; these specify exactly one of the 8 columns of seats on the plane (numbered `0` through `7`). The same process as above proceeds again, this time with only three steps. `L` means to keep the lower half, while `R` means to keep the upper half.

For example, consider just the last 3 characters of `FBFBBFFRLR`:

• Start by considering the whole range, columns `0` through `7`.
• `R` means to take the upper half, keeping columns `4` through `7`.
• `L` means to take the lower half, keeping columns `4` through `5`.
• The final `R` keeps the upper of the two, column `5`.

So, decoding `FBFBBFFRLR` reveals that it is the seat at row `44`, column `5`.

Every seat also has a unique seat ID: multiply the row by 8, then add the column. In this example, the seat has ID `44 * 8 + 5 = 357`.

Here are some other boarding passes:

• `BFFFBBFRRR`: row `70`, column `7`, seat ID `567`.
• `FFFBBBFRRR`: row `14`, column `7`, seat ID `119`.
• `BBFFBBFRLL`: row `102`, column `4`, seat ID `820`.

As a sanity check, look through your list of boarding passes. What is the highest seat ID on a boarding pass?

### Importing the data

Every Advent of Code participant gets their own set of data. I copied my data and went through my usual process of bringing it into Python. This involves pasting it into a triple-quoted string and assigning it to the variable `raw_input`, and then splitting it using the newline character as a delimiter, producing a list named `split_input`: