Day 12

Posted on Wed 15 December 2021 in aoc2021 • Tagged with python

See problem here.

If this problem was hard for you, you are not alone.. I hope to clear things up in this post.

Background

First, let's go over some general graph traversal algorithms.

def bfs(graph, start, end):
    # return True if there exists path from start to end
    q = [start …

Continue reading

Day 07

Posted on Tue 07 December 2021 in aoc2021 • Tagged with js, python

See problem here.

The basic idea is to calculate the total cost for some positions to position m.

function fuel_cost(positions, m, method) {
    var cost = 0;
    for (var c of positions) {
        if (method === "constant") {
            cost += Math.abs(m - c);
        }
        else { // "step"
            cost += Math.abs(m - c) * (Math.abs(m - c …

Continue reading

Day 06

Posted on Mon 06 December 2021 in aoc2021 • Tagged with js, python

See problem here.

My initial approach was to track all of the fish. We decrease number of days for each fish by 1 until it reaches 0. Then we reset it to 6 for existing fish and add a new fish with value 8. This works fine but it is …


Continue reading