r/adventofcode • • Dec 10 '21

SOLUTION MEGATHREAD -🎄- 2021 Day 10 Solutions -🎄-

--- Day 10: Syntax Scoring ---


Post your code solution in this megathread.

Reminder: Top-level posts in Solution Megathreads are for code 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:08:06, megathread unlocked!

65 Upvotes

982 comments sorted by

View all comments

Show parent comment

7

u/duncan-udaho Dec 10 '21 edited Dec 13 '21

Man, I gotta get better with Rust. Yours looks sooooo much cleaner than mine.

I didn't know you could do a multi match like that (match c { '('|'['|'{'|'<' => ...) and I have yet to use fold successfully without reference, so I'll give that a try here tomorrow.

I really just wanted to comment on your post to say thanks. I've been finishing each puzzle on my own, then I commit it, but afterward I go back and refactor using all the tips I pick up from this thread. I've been referencing your posts a lot for that refactoring, and have learned a bit from you so far, so thanks! I appreciate you posting this.

4

u/SuperSmurfen Dec 10 '21

Thanks, I really appreciate you reaching out and saying that!

Rust's match statement is amazing, one of the best parts of the language. You can even do "multi-matching" inside of an option for example. Another nice feature is "guard clauses":

Some(2|3|5|7) | None  => {...}
Some(c) if c % 2 == 0 => {...}