[Blogging Intensifies]

Technology, Projects, Linux, Coding, Internet of Things, Music, Books, Life...

  • About

Advent of Code 2020 – Day 1

December 1, 2020

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.

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to email this to a friend (Opens in new window)

Related

Posted in: Advent of Code 2020 Tagged: Advent of Code 2020, Coding, Python
Twitter LinkedIn email
Instagram Instagram Instagram
GitHub
JoshMiller.net
Lameazoid.com
Photo Gallery

Categories

  • ►Devices (18)
    • Android (3)
    • PCs (3)
    • Synology NAS (4)
    • Windows Phone (3)
  • ►Lifestyle (22)
    • Books (4)
    • Language (1)
    • Music (10)
    • Organizing (5)
  • ▼Maker (65)
    • Arduino (8)
    • CHIP (5)
    • ▼Coding (25)
      • Advent of Code 2020 (12)
    • Hardware (1)
    • Home Security (2)
    • My DIY Projects (3)
    • Non-Tech (2)
    • Raspberry Pi (9)
    • The Basement (6)
    • The Cloud (3)
  • ►Opinion/Editorial (8)
    • Copyright and You (3)
    • Privacy (2)
    • Social Media (1)
  • ►OS (3)
    • Linux & Open Source (1)
    • Windows (2)
  • ►Technology (5)
    • Security (1)
  • ►What I Use (10)
    • Hardware (3)
    • Photography (2)
    • Software (5)

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 611 other subscribers

Hosted on…


Help support hosting with our referral link!

Copyright © 2021 [Blogging Intensifies].

Me WordPress Theme by themehall.com

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.