This repository has been archived by the owner. It is now read-only.
Elixir solution to Advent of Code 2018 Day 1
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
lib
test
.formatter.exs
.gitignore
README.md
mix.exs

README.md

Advent of Code 2018, Day 1

Solution in Elixir, by Scott Swezey.

Input your puzzle

For simplicity, I've placed my code into the @puzzle module attribute in the Frequency module. You can update it with your code, or pass your code as the first argument in Frequency.sum_it/1 or Frequency.remember_it/1.

In both cases, the puzzle should be copy/pasted as is: as a binary of text seperated by newlines.

Part 1

Start an iex shell using iex -S mix

IO.puts Frequency.sum_it(puzzle)

Part 2

Solving this puzzle required a GenServer which will need to be started before running the Frequency.remember_it/1 function. The test suite handles starting the the History GenServer for you, and resetting the state between every test.

Start an iex shell using iex -S mix

{:ok, _pid} = History.start_link()
IO.puts Frequency.remember_it(puzzle)

Potential improvements

  • The test suite seems sufficient, but I haven't looked for edge cases or given it more complex test input.
  • I don't like my module and function names. Given more time and a real problem in this domain, I suspect better names could be found.
  • If this were a real project, I'd improve the puzzle input and start the History GenServer on app startup. I might consider some kind of REPL for solving the two parts of the puzzle.
  • On that same note, the mix.exs file needs some love to make this more usable.
  • I hate how I've handled looping in the Frequency.remember_it/1 function in the event a solution isn't found on the first pass. Unfortunately, it got late and I decided to not refactor this since it was working and I need to sleep.

Contributions, Forking, Discussion

  • No issues, PRs, or other contributions will be accepted for this project.
  • Forking this project is discouraged. Try to solve it on your own.
  • Discussion is welcome via my Twitter account: @ScottSwezey.