NobbZ

NobbZ

Advent of Code - Day 2

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.

Most Liked

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:

sorentwo

sorentwo

Oban Core Team

I’m doing my problems in Elixir this year as well: http://github.com/sorentwo/aoc_2018

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.

Where Next?

Popular in Challenges Top

bjorng
This topic is about Day 10 of the Advent of Code 2021. We have a private leaderboard (shared with users of Erlang Forums ): https://adv...
New
stevensonmt
Trying to get more facility with dynamic programming concepts on Leetcode and having an issue I can’t find a way around. It’s a chutes an...
New
dominicletz
This topic is about Day 8 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/le...
New
Aetherus
The second part of today’s puzzle is very misleading. FYI, each of the ghosts has only one possible position that ends with a "Z" on its...
New
bjorng
This topic is about Day 2 of the Advent of Code 2021. We have a private leaderboard (shared with users of Erlang Forums): https://adven...
New
cblavier
Hey there :wave: No magic or algorithmic finesse today, I just finished the challenge and I my code is quite slow (1sec for part1, 3se...
New
bjorng
Here is my solution for day 1 of Advent of Code: defmodule Day01 do def part1(input) do all = parse(input) {first, second} = E...
New
Aetherus
Today’s problem is really tense. I don’t think I can do it without libgraph.
New
bjorng
Note: This topic is to talk about Day 4 of the Advent of Code 2019. There is a private leaderboard for elixirforum members. You can join...
New
cblavier
Hi, there :wave: Today, I felt it was way more challenging! I went through part2 thanks to Agent based memoization (without memoization ...
New

Other popular topics Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New

We're in Beta

About us Mission Statement