NobbZ

NobbZ

Note by the Moderators: This topic is to talk about the Day 2 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.


This is my todays code:

I’m not quite happy with it though, but it runs in ~4ms/~8ms, so I leave it as is for now.

Showing Posts 1 to 3

sorentwo

sorentwo

Oban Core Team

I’m doing my problems in Elixir this year as well: GitHub - sorentwo/aoc_2018: Advent of Code 2018 · GitHub

My solution today seems a little different from the others I’ve seen. I made use of String.myers_difference/2 for the second part:

  def common(addresses) do
    pairings = for add_a <- addresses, add_b <- addresses, add_a != add_b, do: {add_a, add_b}

    Enum.reduce_while(pairings, nil, fn {add_a, add_b}, _ ->
      case String.myers_difference(add_a, add_b) do
        [eq: _, del: << char :: size(8) >>, ins: _, eq: _] ->
          {:halt, String.replace(add_a, IO.chardata_to_string([char]), "")}

        _ -> {:cont, nil}
      end
    end)
  end

There are two other possible edit scripts that could have matched (first character or last character being the difference), but this worked for my inputs.

yawaramin

yawaramin

I’m pretty happy with my solutions so far, especially for Day 2 Part 2 I felt I was able to take advantage of a few things, especially a comprehension to structure it nicely:

debajit

debajit

I had a lot of fun doing Day 2 Part 2.

I like how this one turned out — reasonably small and clean.

I’ve learned that finding the right functional operation (Enum.find_value in this case) really helps keep the code small (and easy to reason about). (String.myers_difference helped, of course. I wrote my first version with MapSet (and set difference and intersections), which interestingly worked for the example case, but did not work with the large input file, so I ended up using String.myers_difference)

— 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
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; 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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews