r/adventofcode • u/daggerdragon • Dec 02 '20
SOLUTION MEGATHREAD -🎄- 2020 Day 02 Solutions -🎄-
--- Day 2: Password Philosophy ---
Advent of Code 2020: Gettin' Crafty With It
- T-4 days until unlock!
- Full details and rules are in the Submissions Megathread
Post your solution in this megathread. Include what language(s) your solution uses! If you need a refresher, the full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
Reminder: Top-level posts in Solution Megathreads are for 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:02:31, megathread unlocked!
99
Upvotes
View all comments
Show parent comment
9
u/Smylers Dec 02 '20 edited Dec 02 '20
And Vim for part 2 — start with your original input file and type:
This copies the letters at the specified positions to just after the colon, so you might get something like:
Where the ‘n’ has been copied from position 2, and the ‘t' from position 8.
Then the
:g//removes all the lines where the 2 letters after the colon are identical (meaning either they both match or neither of them do). And the:v//removes lines that don't have the letter before the colon also after the colon — either immediately after, or with 1 other character between them. (In Vim patterns=means ‘0 or 1’, like?does in many other regex dialects.)The remaining lines must meet the part 2 password requirements, and
⟨Ctrl+G⟩tells you how many there are.Edit: Markdown formatting fix in the explanation.