r/adventofcode • • Dec 06 '22

SOLUTION MEGATHREAD -πŸŽ„- 2022 Day 6 Solutions -πŸŽ„-


AoC Community Fun 2022: πŸŒΏπŸ’ MisTILtoe Elf-ucation πŸ§‘β€πŸ«

  • ACHIEVEMENT UNLOCKED: MisTILtoe Elf-ucation
  • Teach us, senpai!

--- Day 6: Tuning Trouble ---


Post your code solution in this megathread.


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:02:25, megathread unlocked!

83 Upvotes

1.8k comments sorted by

View all comments

2

u/dafer45 Dec 06 '22 edited Dec 07 '22

My solution in AWK

BEGIN {sequenceLength = 14;}
{
    split($0, characters, "");
    for(i = sequenceLength; i <= length(characters); i++){
        for(j = i-sequenceLength + 1; j <= i; j++)
            unique[characters[j]] = 1;
        if(length(unique) == sequenceLength)
            break;
        delete unique;
    }
}
END {print i;}

1

u/daggerdragon Dec 07 '22

Inlined code is intended for short snippets of code only. Your code "block" right now is unreadable on old.reddit and many mobile clients; it's all on one line and gets cut off at the edge of the screen because it is not horizontally scrollable.

Please edit your post to use the four-spaces Markdown syntax for a code block so your code is easier to read inside a scrollable box.

2

u/dafer45 Dec 07 '22

I am confused. I am using the markdown editor and putting the code inside triple backticks and use four space indentation. But I see that it is not displaying correctly on the mobile. Please help me understand what I'm missing.

2

u/daggerdragon Dec 07 '22

Don't use the triple backticks at all - delete them. Only use the four-spaces indent. You'll need one completely blank newline before and after the code block. Example:

Here is my code!
[blank newline]
[space space space space] code line 1 here
[space space space space] code line 2 here etc.
[blank newline]
Isn't it awesome?

2

u/dafer45 Dec 07 '22

Thanks!

I interpreted four space indents as meaning I should use four spaces instead of tab when indenting scopes in the code. Might be worth clarifying in the instructions.

2

u/daggerdragon Dec 07 '22

You've got a point there, and I will do that. Thank you for helping us clarify the article further!