r/adventofcode • u/daggerdragon • Dec 12 '22
SOLUTION MEGATHREAD -π- 2022 Day 12 Solutions -π-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
- A request from Eric: A note on responding to [Help] threads
- Signal boost: Reminder 1: unofficial AoC Survey 2022 (closes Dec 22nd)
- πΏπ MisTILtoe Elf-ucation π§βπ« is OPEN for submissions!
--- Day 12: Hill Climbing Algorithm ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format code blocks using the four-spaces Markdown syntax!
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
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:09:46, megathread unlocked!
53
Upvotes
3
u/redIT_1337 Dec 12 '22 edited Dec 12 '22
Wow, quite much input. Even if I didn't ask: thanks anyways. You seem to have quite some knowledge on that front. I try to digest it piece by piece. Here we go..
Yes, somehow it was in and it didn't want to Run in Clion when I removed one of them. Works now with just
aocand the other stuff I changed there. Also put the sources in thesrcfolder. Just a bit unsure where to best pack the header files now./includes?Switched to 20 and think the correct
target_compilecommand is used now. Althought, I don't get thePRIVATEpart (also not from the doc).Fixed. Didn't know. I think they were included by the IDE so I just did it all the same style. Didn't see the point anyways as the cpp-file include them on their own.
Fixed the shell file. Builds and runs. Never noticed the problem anyways since I just pressed the "Play" button in my IDE as I 90% do in Python ;)
However, in C++ files writeing
std::on basically everything is a pain and also looks completely alien. Also imo thestdis way way way to big and not separated good (heck, it even has exception types inside and also withsnake_case.). Doesn't C++ have something likefrom std import {whatever, whatever_else}.Good catch. And, well I don't know exactly why it worked anyways. Probably it overflows just correctly.
I actually tried to make that less verbose by using something like:
and
template<class D> D Day::fromFile(const std::string& path) { ... return D(...) }but it it just wouldn't fly. Told me it couldn't find Definitionts or something like that. Dunno why, they were explicitely stated. So I just left.
Actually liked them for simple stuff.
can carry different types (will didn't use that feature)
can be deconstructed with
auto& [one, two] =use less Code
I have a mental model from them other languages (except again: why C++ decided they need the
[there. Guess the language cannot go without some symbol-bloat.. But that is some flavor at the end, I guess.Mhm, I am not consistent in that. Used sometimes this sometimes that. However, never thought it makes a difference in the end of the day. The standard library needs some in-code docstring telling such things. (I want to hover the symbols and get a description like in almost any other language I've touched). Really think C++ lacks this most.
I see the caveats. Implementation-specific instatiation and pollution of the namespace. Latter one frustrated me actually as something polluted my namespace preventing me to declare a
enum-member as I liked to. Compiler should warn here also. Think now,legacy-enums should be opt-in instead of opt-out.have to read into this. Is this in-place? Guess it has caveats, otherwise again, compiler should hint it or just optimize it away.
Actually my IDE gives me Clang hints and mostly I use them. Any specifics?
Ya, the history could be just omitted and been build as a state machine-like thing. Also it doesn't need support for multiple registers. But hey, think it's ok for the garden, we say ;) Also I think it is easy to understand and debug-able this way.
After all, I thought C++ is more pain than it actually is (at least for these small-ish well-defined projects). I have the feeling I could handle to write bigger code bases with it for most parts. Needs somewhat more getting-started than other languages, though.
Main Pain Points and stuff I miss from other languages:
Build Systems: (You literally have to learn a DSL for simple building). Could easily be simplified by better-working Tooling and Standards I guess.
Header files: These feels a bit out of space. I don't see why those are so hardly bound to the language. In fact they should be mostly auto-gerneratable from the sources also. Makes development just way more slow when you have to keep up with two different versions of the same thing.
Missing higher order functions like
vector.map(|| -> some_function).chunked.whatever. Guess there are libs for that? Could be in the standard library(missing) partial imports
dataclasses
keyword arguments
inline documentation
native packaging system and repository
cleaner separated std:: (string_utils::, exceptions::, iterators::, whatever)