Advent of Code 2019 - Day 1

Note: This topic is to talk about Day 1 of the Advent of Code 2019.

5 Likes

I used Advent of Code last year to learn some Elixir. Since I havenā€™t used Elixir much this year, I am using AOC 2019 as an opportunity to refresh my Elixir skills.

Here is my solution for my solution for Day 1.

7 Likes

There is room for improvement, eg by using Enum instead of Stream, and probably even more by doing manual recursion, but as Iā€™m in the area of 0.05ms for part 2, Iā€™ll just leave it as is.

2 Likes

Thatā€˜s a cool Boilerplate you got there. Gonna borrow it next time :nerd_face:

3 Likes

I will try something new this year, will live stream solving the challenges on Twitch. Today the stream starts at 2pm CET (in 1 hour 15 mins), hereā€™s my channel :slight_smile: Will be using Elixir, and maybe Rust for some challenges.

Last yearā€™s solutions are here.

P.S. First day solution is here. Forgot to switch on ā€œsave past broadcastsā€, will not forget next time :wink: Next stream will be on Tuesday at 7pm CET.

5 Likes

Hereā€™s my take.

3 Likes

Hey guys,

hereā€™s mine github repo for this aoc2019: alvises/aoc2019

And day1.ex

Iā€™m possibly going to have to refactor my repository structure but in any event my solution is here.

The aoc package is going to hold common code such as functions to load data from files.

Each day will be its own application and, compared to most I imagine, verbose. I like adding tests and some documentation.

1 Like

I am so pleased that SaÅ”a is doing this again this year. His code tends to be incredibly compact and contains some lovely approaches which Iā€™d not have thought about. Today Iā€™ll be learning more about streams from him. :grin:

3 Likes

I did mine in iex and translated to code after the fact: https://github.com/keathley/advent_of_code_2019/blob/master/day1.exs.

My own stab at Day 1:

2 Likes

This year Iā€™m going to do my best to take a stab at this, using Elixir of course! Hereā€™s my Day 1 solutions. Iā€™m aiming for idiomatic elixir, thatā€™s not too code-golfy.

Finished my pretty naive implementation as well: https://github.com/dimitarvp/aoc2019.ex/blob/master/lib/day1.ex

I opted for:

  • Common module helpers, for now just File.stream!-ing standardised file names from the priv/ project directory. You know, convenience.
  • Have a fuel and total_fuel functions, the latter being the recursive one.
  • Introducing doctests that exactly match the examples given in the task description.

Again, pretty naive and straightforward. Comments welcome!

2 Likes

@sasajuric Almost like mine! I also opted for a helper module that streams the file that maps to the day in question.


@patrickcarver:

  def iterate(mass) do
    mass
    |> Stream.iterate(&fuel_required/1)
    |> Enum.take_while(& &1 > 0)
    |> tl() # remove the module mass which would be the first in the list
    |> Enum.sum()
  end

Thatā€™s really clever, I love it!


@NobbZ Really solid code.

2 Likes

My solution.

3 Likes

Somebody in the HackerNews thread posted quite readable bash solution.

2 Likes

Yeah, I have a few common helpers, but I try to keep this as small as I can. So mostly reading the file input, and a few frequently needed enum helpers.

Doing the challenge in Elixir this year. My day one solution is a little ugly but gets the job done. https://github.com/agundy/advent_of_code/blob/master/2019/solutions/lib/day_1.ex

2 Likes

Nice. One of my top priorities are terseness and readability. But I can give up some terseness in exchange for code thatā€™s quicker to parse for any random reading human, and it seems you are the same.

Brofist? :fist_right: :fist_left: :052:

1 Like

My solution was pretty vanilla.

If the boilerplate strategy above holds, I might have to sneak something like that in!

1 Like