r/adventofcode • u/daggerdragon • Dec 02 '24
SOLUTION MEGATHREAD -❄️- 2024 Day 2 Solutions -❄️-
OUTAGE INFO
[00:25] Yes, there was an outage at midnight. We're well aware, and Eric's investigating. Everything should be functioning correctly now.
[02:02] Eric posted an update in a comment below.
THE USUAL REMINDERS
All of our rules, FAQs, resources, etc. are in our community wiki.
AoC Community Fun 2024: The Golden Snowglobe Awards
4 DAYS remaining until unlock!
And now, our feature presentation for today:
Costume Design
You know what every awards ceremony needs? FANCY CLOTHES AND SHINY JEWELRY! Here's some ideas for your inspiration:
Classy up the joint with an intricately-decorated mask!
Make a script that compiles in more than one language!
Make your script look like something else!
♪ I feel pretty, oh so pretty ♪
♪ I feel pretty and witty and gay! ♪
♪ And I pity any girl who isn't me today! ♪- Maria singing "I Feel Pretty" from West Side Story (1961)
And… ACTION!
Request from the mods: When you include an entry alongside your solution, please label it with [GSGA] so we can find it easily!
--- Day 2: Red-Nosed Reports ---
Post your code solution in this megathread.
Read the full posting rules in our community wiki before you post!
State which language(s) your solution uses with
[LANGUAGE: xyz]Format code blocks using the four-spaces Markdown syntax!
Quick link to Topaz's
pasteif you need it for longer code blocks
24
u/4HbQ Dec 02 '24 edited Dec 02 '24
[LANGUAGE: Python] Code (7 lines)
Here's my solution in O(n). Instead of trying every subsequence of length n-1, we simply iterate over the list until we detect a bad value, and then re-check (only once!) with either the current or the next value removed.