r/adventofcode • u/daggerdragon • Dec 05 '16
SOLUTION MEGATHREAD --- 2016 Day 5 Solutions ---
--- Day 5: How About a Nice Game of Chess? ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
STAYING ON TARGET IS MANDATORY [?]
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
4
u/askalski Dec 05 '16 edited Dec 05 '16
It's subtracting
15 - shift_bitsusing addition and 2's complement (-n == ~n + 1), so15 - shift_bits == 15 + (~shift_bits + 1) == 16 + ~shift_bits. This result is the number of bits to copy from input to output.Here's a Perl version (and example output) that prints the intermediate values each iteration of the loop.