logo

adventofcode

Code used to solve https://adventofcode.com/, one branch per year git clone https://hacktivis.me/git/adventofcode.git

day2.ex (424B)


  1. defmodule Day2 do
  2. # add
  3. def opcode([1, pos1, pos2, store], tokens) do
  4. List.replace_at(tokens, store, Enum.at(tokens, pos1) + Enum.at(tokens, pos2))
  5. end
  6. # multiply
  7. def opcode([2, pos1, pos2, store], tokens) do
  8. List.replace_at(tokens, store, Enum.at(tokens, pos1) * Enum.at(tokens, pos2))
  9. end
  10. # halt
  11. def opcode([99, _, _, _], _) do
  12. :halt
  13. end
  14. # noop
  15. def opcode(_, _) do
  16. :noop
  17. end
  18. end