Mostly code

## Advent of Code 2019: Day 7

09 Dec 2019

More intcode computing! Without any modifications to the computer, and a quick search for an algorithm to make permutations, which, like, I just didn’t want to have to figure out, and I am ready to solve this.

defp permutations([]), do: [[]]

defp permutations(list),
do: for(elem <- list, rest <- permutations(list -- [elem]), do: [elem | rest])

Once my permutations are generated, all that’s left is to amp things up.

## Advent of Code 2019: Day 6

08 Dec 2019

Today, I’m pretty much playing Kerbal Space Program and planning some orbital trajectories. As shown in the problem itself, a tree is the perfect way to represent the orbits, so building one shouldn’t be too hard.

defp build_tree([], node), do: node

defp build_tree(list, p) do
connections = Enum.filter(list, &String.starts_with?(&1, p))

list = Enum.filter(list, fn x -> x not in connections end)

c =
connections
|> Enum.map(fn x -> x |> String.split(")") |> List.last() end)
|> Enum.map(fn x -> build_tree(list, x) end)

%{p: p, children: c}
end

list here is the list of connections I’m given, in the form of AAA)BBB, and p is the object that I am finding satellites of. First, I find all the connections by filtering the list for lines that start with the payload, and then for each child I build a tree with that child as the root. Once all the lines are filtered out, the tree is complete.

## Advent of Code 2019: Day 5

06 Dec 2019

In which previous bad code shoots me in the foot.

This was a continuation of the puzzle from day 2. If you don’t recall, I made a small intcode computer that was able to add, multiply, and stop. I need to augment this computer by adding the ability to take input and produce output. I also need to handle “parameter modes” and expanded intcodes

## Advent of Code 2019: Day 4

05 Dec 2019

This one didn’t seem too bad, but I can’t help but feel there’s a “clever” solution that alludes me. Some sort of funky math theorizing that I just don’t know about.