r/adventofcode • u/daggerdragon • Dec 06 '20
SOLUTION MEGATHREAD -🎄- 2020 Day 06 Solutions -🎄-
NEW AND NOTEWORTHY
- /u/jeroenheijmans is back with the Unofficial AoC 2020 Participant Survey!
- /u/maus80 is back with an interactive scatterplot of the global leaderboard!
Advent of Code 2020: Gettin' Crafty With It
- UNLOCKED! Go forth and create, you beautiful people!
- Full details and rules are in the Submissions Megathread
- Make sure you use one of the two templates!
- Or in the words of AoC 2016: USING A TEMPLATE IS MANDATORY
--- Day 06: Custom Customs ---
Post your solution in this megathread. Include what language(s) your solution uses! If you need a refresher, the full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:04:35, megathread unlocked!
66
Upvotes
View all comments
Show parent comment
1
u/Arknave Dec 06 '20
This is actually my first time writing C, so I don't think there's anything particularly advanced here. Here's the output when running this through clang-format (I don't save any intermediate stages when I'm writing these)
The only language features in use are arrays, pointers, and the deprecated
getsfunction. One trick I employed here was to set a pointereto the end of theharray. Then instead of looping over the indices0..26, I instead set a pointerktohand increment it until it hits the end pointer. Normally this would take more characters than the index based loop, but since I loop over theharray twice (once to reset it and once to update the answers), this shaves off a whopping 2 characters.I also shaved off a character by setting
p = q = 0in the first part of a for loop instead of assigning when I declared them. I could have saved even more characters by declaring them globally, but then I ran into issues fitting themainandchartokens around the whitespace.Other things like
h[-97 + *k]which look really unnatural were just written so the 1 and 2 character tokens ended up where I wanted them.Hopefully this was helpful, The README on my git repo lists a few of the tricks I've used in other puzzles to add extra characters to lines, and all of my other ascii art
abominationscreations.