bjorng

bjorng

Erlang Core Team

Advent of Code 2019 - Day 4

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 it by following this link and entering the following code:

39276-eeb74f9a

Most Liked

bossek

bossek

defmodule Day04 do
  import Enum, only: [filter: 2, chunk_by: 2, any?: 2, sort: 1]
  def run(cnd), do: 124_075..580_769 |> filter(&valid?(Integer.digits(&1), cnd)) |> length()
  defp valid?(ds, cnd), do: chunk_by(ds, & &1) |> any?(&cnd.(length(&1))) and sort(ds) == ds
end

IO.inspect(Day04.run(&(&1 >= 2)), label: "part 1")
IO.inspect(Day04.run(&(&1 == 2)), label: "part 2")
aaronnamba

aaronnamba

For AoC, I pick a language I want to get to know better. This year it’s Elixir. I came from the Ruby world (by way of a short detour through Crystal-land). I have already launched a Phoenix-based CMS (closed source for now, unfortunately), but I am still far from fluent.

So I’m sure my solutions won’t be ideal, but I thought I’d post them anyway, since i have enjoyed reading through the various solutions posted here for the first 3 days.

Day 4 Solution

As I was writing this, Aetherus’s post appeared and I realized I forgot about the :discard option on chunk_every… oh well.

sasajuric

sasajuric

Author of Elixir In Action

My solution is here.
I decided I don’t want to brute-force this, so I made a function which computes the next valid password, on top of which I can build a stream of valid passwords.

Where Next?

Popular in Challenges Top

igorb
I found today a bit tedious: advent-of-code-2024/lib/advent_of_code2024/day15.ex at main · ibarakaiev/advent-of-code-2024 · GitHub.
New
LostKobrakai
This one has been quite the ride. Struggled at first to find a good data format to suite the problem. I really like how that turned out b...
New
Aetherus
This topic is about Day 5 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/le...
New
Aetherus
Today’s problem is really tense. I don’t think I can do it without libgraph.
New
gangstead
This is my second year doing AoC in Elixir and my first year doing it with Livebook. When I was doing just plain Elixir I usually set up...
New
Aetherus
This topic is about Day 15 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/l...
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
seeplusplus
This one was much easier for me than yesterday’s. Part 1 runs in 22ms and part 2 runs in ~3s. defmodule BridgeRepair do def parse_inpu...
New
Aetherus
This topic is about Day 16 of the Advent of Code 2020 . Thanks to @egze, we have a private leaderboard: https://adventofcode.com/2020/l...
New
christhekeele
Setting this down for the night, as after a quick naive solve for quick part 1 I realize that part 2 is by design computationally expensi...
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

We're in Beta

About us Mission Statement