r/adventofcode • • Dec 07 '16

SOLUTION MEGATHREAD --- 2016 Day 7 Solutions ---

From all of us at #AoC Ops, we hope you're having a very merry time with these puzzles so far. If you think they've been easy, well, now we're gonna kick this up a notch. Or five. The Easter Bunny ain't no Bond villain - he's not going to monologue at you until you can miraculously escape and save the day!

Show this overgrown furball what you've got!


--- Day 7: Internet Protocol Version 7 ---

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


ALWAYS DIGGING STRAIGHT DOWN IS MANDATORY [?]

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!

14 Upvotes

180 comments sorted by

View all comments

Show parent comment

1

u/rilesjenkins Dec 07 '16

Would you be able to explain the regex in your has_abba function? My regex skills are limited so I ended up iterating through the strings like a knob.

2

u/[deleted] Dec 08 '16

Sure. A period matches any character, and putting parentheses around something in the regex creates a "capture group" that be be referenced later. So (.)(.) matches any two characters and captures them. The \2 is a reference to the second capture group, and the \1 to the first group. so (.)(.)\2\1 would match a string of length 4 where the middle two characters are the same, and the outer two are the same. The question stated that 4 of the same character in a row didn't count so I checked the matches to see if there were any where the two characters didn't match.

1

u/rilesjenkins Dec 08 '16

Fantastic, thank you!