Advent of Code

Advent of Code is a yearly set of programming challenges, released each day leading up to Christmas, presenting increasing harder challenges. I will be completing it over the next few weeks, though not properly in time due to me having exams and going away.

My Plan

My plan for this year is that for each week block of challenges I want to try exploring a different programming language, supporting my learning.

The languages I plan to use are:

  • Python (Day 1)
  • Erlang (Days 2-8)
  • Common Lisp (Days 9-16)
  • Java (Days 17-24)
  • Undecided as of yet! (Day 24+ any extra catchup needed)

This plan may fall through, especially as I also want to work through Learn You An Erlang and Genetic Algorithms With Python

Day 1

The code for day 1 is below (and on github):

import operator

# Part 1
with open("input","r") as f: puzzle_input = f.read()

values = puzzle_input.split()

left = []
right = []

for i in range(len(values)):
    if i % 2 == 0:
        left.append(int(values[i]))
    else:
        right.append(int(values[i]))

left.sort()
right.sort()

diff = list(map(operator.sub, left, right))
diff = list(map(abs, diff))

print(sum(diff))

# Part 2
unique = list(set(left)) # Each number in left list
occurences = {}

for item in unique:
    occurences[item] = right.count(item)

print(occurences)

similarity = 0

for key, value in occurences.items():
    similarity += key * value

print(similarity)