🎄 Christmas Coding with Elixir, Day 1

Advent Of Code 2018

Santa: Big Elixir fan

The Puzzle: Part 1

Solving It

So part 1 is pretty simple. We need to parse a list of positive and negative integers and then sum them together.

cat input.txt | ./advent1.1.exs
$ cat input.txt | ./advent1.1.exs
439

The Puzzle: Part 2

Solving It

Ok! So now it gets a little trickier. In Ruby, I’d use Enumerable#cycle to give an infinite stream of frequencies and then use return to break out early when I found one that’d been seen before.

$ cat input.txt | ./advent1.2.exs
124645

Summary

So that was fun, and a little trickier than I was expecting for day 1! I’ll be filing away Enum.reduce_while/3 for future reference 😁

--

--

Señor Developer specialising in open-source languages, particularly Ruby & Elixir. seanhandley.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sean Handley

Señor Developer specialising in open-source languages, particularly Ruby & Elixir. seanhandley.com