Papey

Papey

This topic is about Day 20 of the Advent of Code 2020 .

Thanks to @egze, we have a private leaderboard:
https://adventofcode.com/2020/leaderboard/private/view/39276

The join code is:
39276-eeb74f9a

Most Liked

Papey

Papey OP

Just the part 1 for now.

I did not reconstruct the map, just looked at corners. It’s ugly and verbose but it works.

Now on part 2, but I already find the sea monster, it’s my function that finds corners :sweat_smile:

  def find_corners(tiles) do
    # Map all edges to corresponding tiles
    Enum.reduce(tiles, %{}, fn {id, tile}, acc ->
      edges = edges(tile)

      Enum.reduce(edges ++ Enum.map(edges, &flip/1), acc, fn edge, acc ->
        {_old, acc} =
          Map.get_and_update(acc, edge, fn old ->
            if old do
              {old, [id | old]}
            else
              {old, [id]}
            end
          end)

        acc
      end)
    end)
    # Filters out singleton
    |> Enum.filter(fn {_edge, ids} -> length(ids) == 1 end)
    # A list of one is just the element inside that list
    |> Enum.map(fn {edge, [id]} -> {edge, id} end)
    # Reverse the reduce to find how many edges maps this tile id
    |> Enum.reduce(%{}, fn {_edge, id}, acc ->
      {_old, acc} =
        Map.get_and_update(acc, id, fn old ->
          if old do
            {old, old + 1}
          else
            {old, 1}
          end
        end)

      acc
    end)
    # filter out candidates
    |> Enum.filter(fn {_id, match} -> match > 2 && match < 5 end)
    |> Enum.map(fn {id, _match} -> id end)
  end

https://github.com/papey/aoc/commit/28227b000a7dbe2ddfc122c6e36a6d9f7d3f4167

lud

lud

I got is working this afternoon, and I’ve just cleaned the code a little bit.

Not very proud of this solution as it is messy and hard to read. But it completes in 15ms (not counting transforming the raw input into list of tiles (which are lists of lists of chars).

bjorng

bjorng

Erlang Core Team

I tried to leverage my corner-finding code from part 1 for part 2, but I didn’t make much progress. After sleeping on it I decided to start over with another approach for part 2. I spent most of the time getting the tile combining to work. After that, it was fairly easy to implement the search for the sea monster.

Here is my solution.

Last Post!

cblavier

cblavier

Wow I finally cracked day 20, such a bummer :exploding_head:
So many stupid mistakes (like searching for monsters for hours with rows in random y order …)

At least my code is performing well (about 100ms)

My code for Part1 and Part2

Where Next? Top

Trending in Challenges Top

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
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
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews