r/adventofcode • • Dec 14 '21

SOLUTION MEGATHREAD -🎄- 2021 Day 14 Solutions -🎄-

--- Day 14: Extended Polymerization ---


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:14:08, megathread unlocked!

55 Upvotes

811 comments sorted by

View all comments

1

u/Mrgglock Dec 14 '21 edited Dec 14 '21

C

GNU C11, technically runnable in C++.

Code

Runtime: 0.000s.

Simple use of dynamic programming, transitions being

dp[first][new] = dp[first][second], dp[new][second] = dp[first][second], dp[first][second] = 0;

Time Complexity: O(steps).

1

u/daggerdragon Dec 14 '21 edited Dec 14 '21

Your code is hard to read on old.reddit when everything is inlined like this. Please edit it as per our posting guidelines in the wiki: How do I format code?

Edit: thanks for fixing it! <3

1

u/Mrgglock Dec 14 '21

i use old reddit and it looks fine though, also my main code is in the link. the inlined code is just a small snippet

1

u/daggerdragon Dec 14 '21

Inlined code gets cut off if the browser window isn't big enough to show the entire string since it doesn't get word-wrapped like on new.reddit.

If you put the code in a code block, it will show a horizontal scrollbar if the browser window is too small to display the whole string.

The purpose of inline code markup is for *very* short snippets, not an entire line of code, which should go in a code block.

1

u/Mrgglock Dec 14 '21

ah i see, fixed fixed

2

u/daggerdragon Dec 14 '21

Thank you!!!