bjorng
Erlang Core Team
This topic is about Day 14 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
Trending in Challenges
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
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
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
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 31 to 22- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
stevensonmt
FINALLY GOT IT
I’ve done a half dozen approaches to the branching/flat mapping portion of applying the mask, but in the end there was something squirrelly about how I was processing the input. Once I broke down and used Nimble Parsec it just worked. UGGGGH.
stevensonmt
I’ve narrowed down the error (at least I think so) but still don’t know why it’s happening. For the dataset:
I get a sum that is off by the sum of values of the 4th memory entry (
mem[49386] = 7440645) after the mask is applied. Applying the mask generates a correct value (I checked using successful algorithms posted in this thread). For some reason this address is being duplicated by my algorithm. I really suspect it is in this bit:The initial value for
accis a list containing the list of digits of the original address in binary after applying the one mask and padding to length 36. The argument[x | rest]is a list of indices in the mask at which an “X” was identified.I cannot understand what is special about this one memory address that it gets duplicated. If I remove that one address I get the same answer as the successful algorithm. When I use the entire dataset my solution is off by more than just the value of this one entry, so it is clearly not JUST this value that is problematic. My hope is that someone can help me identify why this entry is problematic so that I can understand the flaw in my logic that generates what currently seems to me a random error.
Full code here: flawed Advent of Code 2020 day 14 part 2 · GitHub
stevensonmt
Thanks for taking the time to review the code. I really appreciate it. For some reason I remember struggling to pattern match on
process_masks([head | []], acc)but I guess I need a case statement to handle that. The trim issue is a true brain fart. Thank you for pointing that out.akash-akya
I took a look at your code, I think your approach is mostly correct, but there seems to be few issues with the code for generating the masks.
Let’s consider generating masks for
0X0, expected000, 010Also, there is another issue, you are using
trim: true,adamu
I made the same mistake originally. You are substituting the Xs in the mask, but what you need to do is substitute the Xs in the masked value.
Step 1: Apply
masktoaddress, to produceresult.Step 2: Permute all the Xs in the
result, which produces:So you need to make sure your mask operation preserves the Xs.
stevensonmt
no dice. I’m going to have to re-organize the masking to branch at the apply step rather than at the processing input step. Thanks for your explanation.
This problem is going to haunt me forever, but I just can’t get it to work.
akash-akya
You can try,
((address ||| one_mask) &&& ~~~x_mask) ||| x_maskakash-akya
Like you said, you can’t use &&& to set a bit value to 1.
Basically what you want is an ability to set bit to either 0 or 1 irrespective of other value X. You can’t do that with just one operator.
For setting 0: x &&& 0
For setting 1: x ||| 1
There are many ways to express this logic with different combination of bitwise operators.
Specific to this problem, one way to do it is to set all x bits to zero explicitly at the beginning and do lll with your generated mask
stevensonmt
This horse is dead but I’m going to continue to beat it.
For part 2 I’m trying this to generate the permutations of masks in a tuple with a
one_maskthat sets all the Xs to zero:To apply the masks and build the memory map I’m doing this:
I’m guessing my bitmask operations are a misunderstanding of the prompts rules again because I keep getting it wrong. From the prompt:
which looks to me like an
|||operation for one bits. I think I’m getting it wrong by doing the next&&&operation. But it seems like a mask of000000000000000000000000000000X1001Xwould become four masks ofwhich I think is the problem. Applying an &&& to the all zero mask will be zero, which is incorrect. Inverting the order and applying the x_mask first and then doing an ||| for the one_mask is also wrong though. What’s the concept I’m missing here?
adamu
Seems the link was broken. Take two:
https://github.com/adamu/AdventOfCode2020/blob/main/day14/README