simon

simon

Advent of Code - Day 4

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


Day 4 is in the bag after a bit of a struggle.

For part 1 I had two minutes which has the same count of times asleep for a guard and typically (well, maybe fortunately) my code returned the second minute value which was rejected. I changed my code to look for the earliest minute with the maximum count and all was well.

Part 2 was all down to me and a stupid code mistake but my test using the sample data was passing which threw me off for a while (the same problem happened with part 1). I should probably add my own test data in so that my tests are more comprehensive.

My code was more structured today (I’m using more functions and also a couple of structs) but I’ve still got some Enum.reduce/3 calls in my pipelines which I need to move into their own functions.

And for variety, unlike using regex to parse the data strings which I did yesterday, today I used String.slice/2.

Still need to document things properly however.

Code is at https://github.com/simon-wolf/advent-of-code-2018/blob/master/lib/advent_of_code_2018/day_04.ex

Most Liked

sasajuric

sasajuric

Author of Elixir In Action

I’m not committed to AoC this year, but today I discussed the task with a friend, so I solved it. My solution is here.

Where Next?

Popular in Challenges Top

Aetherus
I tried to use combinatorial to solve today’s puzzles but failed (my brain burned out :exploding_head:). In the end I just used brute for...
New
Aetherus
This topic is about the Advent of Code 2021 - Day 4. Thanks to @bjorng , we now have a new Private Leaderboard. The entry code is: 370...
New
sasajuric
Note by the Moderators: This topic is to talk about Day 5 of the Advent of Code. For general discussion about the Advent of Code 2018 an...
New
lud
At first I was scared but I found is a simple way to compute the sides. defmodule AdventOfCode.Solutions.Y24.Day12 do alias AdventOfCo...
New
sukhmeetsd
All in all, from what I understand, it is better not to use GenServer.cast when we want some concurrent operations to happen for sure, be...
New
Aetherus
Hello, guys. I’m back again, but only for the weekends, maybe. This topic is about Day 13 of the Advent of Code 2020 . Thanks to @egze,...
New
adamu
Probably not the most efficient implementation, because part 1 took >1 ms and part 2 >4ms, but the code was simple enough. def p...
New
Qqwy
Note by the Moderators: This topic is to talk about Day 6 of the Advent of Code. For general discussion about the Advent of Code 2018 an...
New
mattbaker
I’m having so much fun working on the “Protohackers” challenges, I never got into Advent of Code much but this has been amazing. The chal...
New
coen.bakker
Since I started using Elixir, I have benefited greatly from being able to study various open-source projects. The codebase of LiveBook, i...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement