sneako

sneako

Note by the Moderators: This topic is to talk about the first day of the Advent of Code.

For general discussion about the Advent of Code 2018 and links to topics of the other days, see this topic.


Nice one, mine came out quite similar: solution & test

Showing Posts 1 to 10

connorlay

connorlay

Ah nice! Great minds I guess :brain:

simon

simon

I’m doing this too and my solution is very similar to other ones already posted.

I’m fairly new to Elixir and only using it as and when I can for a side-project so I learnt a few new things…

  1. Stream.cycle() was new to me and I had to Google to find it.

  2. Enum.reduce_while was also a new discovery but at least I found this one by looking through the documentation.

  3. List is really slow and MapSet is really fast when checking for existing items. My first solution used List and was fine for the tests I built but I thought that I had a bug and an infinite loop when I ran the full set of data for the challenge. Once it eventually finished I thought that there must be a faster way and looked at the documentation.

Overall it was a fun little challenge and exactly what I hoped it would be… something to get me to learn new things, not just a test to see if I know it all.

I’m really looking forward to watching José’s Twitch streams about these challenges too.

adrianrl

adrianrl

I solved the first one using Enum.reduce:

def part_one(input) do
  input
  |> String.split("\n", trim: true)
  |> Enum.reduce(0, &(String.to_integer(&1) + &2))
end

Saves some keystrokes, but yeah, the code looks horrible compared to the Enum.map version. Would love to see different implementations for the second one.

factoryd

factoryd

I decided to partake as well. Surprise surprise. I ended up with a very similar solution.
https://github.com/trbngr/advent_of_code_2018/blob/master/lib/day_1/chronal_calibration.ex

aleph-naught2tog

aleph-naught2tog

Mine feels a little hacky and relies on Elixir/Erlang being better at tracking unique anything than me. Part 2 of day 1 started off at like ~15s for 137000+ times through; I got it down to 1.5s today a bit ago. https://github.com/aleph-naught2tog/aoc_18/blob/master/day_1/main.ex

debajit

debajit

I just finished my solutions for Day 1. They are here:

The code turned out pretty clean, so I’m happy :slight_smile:

(I spent half the day trying to use Stream.transform, and could not get it to work — I thought it would work like Enum.reduce, but it doesn’t. I was able to get it working with Enum.reduce_while finally. Yay!

The one thing that I learned the hard way is that Stream’s can be piped to Enum functions (like find / reduce / etc) well — I thought any Enum function after a Stream pipeline would try to fetch the entire stream, but I was wrong)

yawaramin

yawaramin

Just finished Day 1 both parts, the fun thing with Advent of Code is that basically anything that deals with reading an input file and doing some calculation on it is a prime candidate for File.stream and then Stream processing–we have it really easy in the Elixir world.

zenw0lf

zenw0lf

Haha, my Day1 Part2, started off at ~171s (¬¬) but got it down to ~0.16s (165ms) :smiley:

arhyth

arhyth

I’ve been working in elixir for a year now and most of the language “constructs” I used in this day’'s solutions including the ones you mentioned were all new to me. My implementation for the second problem used lists and was very slow. I tried it with mapsets after looking at others solutions and wow what a difference.

After this first day, I’m also looking forward to the next days and to Jose’s twitch streams.

luxedo

luxedo

Total Elixir n00b here, So glad my solution is quite close to this! Learnt a few tricks as well thank you

— All posts loaded —

Where Next? Top

Trending in Challenges Top

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews