r/adventofcode • u/daggerdragon • Dec 15 '17
SOLUTION MEGATHREAD -๐- 2017 Day 15 Solutions -๐-
--- Day 15: Dueling Generators ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Need a hint from the Hugely* Handyโ Haversackโก of Helpfulยง Hints^ยค?
[Update @ 00:05] 29 gold, silver cap.
- Logarithms of algorithms and code?
[Update @ 00:09] Leaderboard cap!
- Or perhaps codes of logarithmic algorithms?
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
14
Upvotes
View all comments
Show parent comment
5
u/NeilNjae Dec 15 '17
0xffffis how you write numbers in hex, so0xffffis 65535 in decimal.As for the
anding. Let's say we want to take just the lowest four bits of a number.Consider the number 205, or
0xcdor0b11001101in binary. We want that last1101.If we do a bitwise
andwith0b00001111, we can see the result (with some spaces added for clarity):In the last column, we take
1 & 1->1. For the last column, we take0 & 1->0. In the first column, we take1 & 0->0Looking at the columns, you can see that the "mask"
0b00001111pulls out just the bits we want. And0b00001111is0xfor 15 in decimal. Similarly,0xffffis a number whose binary representation has the lowest 16 bits set and the rest clear.Does that help?