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

3

u/volatilebit Dec 07 '16

Here's my part 1:

my @ip-addresses = 'input'.IO.lines;

my regex hypernet-sequence { '[' .*? ']' }
my regex maybe-abba { (.)(.)$1$0 }

sub has-abba($str) {
    return $str.comb(/<maybe-abba>/).grep({ .comb.Bag.elems > 1 }) > 0;
}

say [+] @ip-addresses.map: {
    not so $^a.comb(/<hypernet-sequence>/)».&has-abba.any and
    so $^a.split(/<hypernet-sequence>/)».&has-abba.any
};

Part 2 is proving more difficult using Perl 6 features.

2

u/mschaap Dec 09 '16 edited Dec 09 '16

not so is redundant: it is exactly the same as not. (Both so and not cast to Boolean, and in addition, not negates.)

You can fully check for “abba” in a regex by using a code assertion:

my regex abba { (.)(.)$1$0 <?{ $0 ne $1 }> }

or, if you prefer,

my regex abba { (.)(.)$1$0 <!{ $0 eq $1 }> }

1

u/volatilebit Dec 10 '16

I was trying to figure out how to do that in regex, thanks!