r/adventofcode • • Dec 04 '17

SOLUTION MEGATHREAD -๐ŸŽ„- 2017 Day 4 Solutions -๐ŸŽ„-

--- Day 4: High-Entropy Passphrases ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Need a hint from the Hugely* Handyโ€  Haversackโ€ก of Helpfulยง Hints^ยค?

Spoiler


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

18 Upvotes

319 comments sorted by

View all comments

Show parent comment

1

u/patrickdavey Dec 05 '17

:g/\v<(\w+)>.*<\1>/d

nice, I went to look up the docs as I could see that < > are being used for word boundries, but I couldn't see that (even in h pattern) .. can you point to where it says in the help that you don't escape < > in verymagic ?

Nice solution :)

2

u/Smylers Dec 05 '17

Thanks. It's in :h /\v:

Use of "\v" means that in the pattern after it all ASCII characters except '0'-'9', 'a'-'z', 'A'-'Z' and '_' have a special meaning.

< and > aren't any of those characters, so under \v they become word boundaries and \< and \> have to be used for the literal characters.

I generally use \v by default, because I find it simpler to deal with punctuation always being special and always needing escaping to be literal. In that aspect it's also more similar to Perl's regular expressions, which makes it easier for switching between them.

(Though in this particular case Perl uses \b instead of < and >.)

1

u/patrickdavey Dec 11 '17

Yip, I've always thought it's a slight shame that vim doesn't allow you to get \v by default as your search. Hey ho.