So, I want to say up front, I don’t know if I will finish this, but I plan to try. Also, while I intend to publish these posts on the respective day of each challenge, I may not actually DO the challenge day of. That is to say, some of these, probably most of these, will be back dated.
Advent of Code is a little 25 day advent calendar of code based challenges. I heard it mentioned on TWIT by Leo Laporte. It can be done in any language or system. There are people who solve these using game engines and such. As this is my first go, and I am not a “professional programmer”, I am doing in in sloppy Python. I’ll be posting my solutions in a Github Repo, which means this challenge serves a second purpose of helping me have an excuse to learn how to better use Github.
The first day’s challenge is pretty simple. Given a list of numbers, figure out which ones add up to 2020 and then multiply them together. Each day has two challenges, based on the same base data set. The data set for each person seems to be different. Here is my solution for Day 1 Part 1:
with open('day1data.txt') as f: lines = [line.rstrip() for line in f] for x in lines: for y in lines: if((int(x)+int(y))==2020): print int(x)*int(y)
Each day of this puzzle (so far) involves reading in a data file, and working with it. My solution involves looping each number, and multiplying it by each other number, and checking for if they sum 2020, then posting the result of multiplying the two numbers.
Part two is essentially the same except it involves three numbers instead of two. This pretty much just meant adding another layer of loop to my loops.
with open('day1data.txt') as f: lines = [line.rstrip() for line in f] for x in lines: for y in lines: for z in lines: if((int(x)+int(y)+int(z))==2020): print int(x)*int(y)*int(z)
This first days’ challenge was pretty simple. The rest of the days, not so much.