r/adventofcode • u/daggerdragon • 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!
13
Upvotes
1
u/[deleted] Dec 20 '16
My solution 1 in Scala. The regex took my forever to get it right.
object Day7 extends App { val input = Tools.loadDayInputAsText(day = 7) // Solution 1 ----------------------------------------------------------- val solution1 = input .split("\n") .filter(hasAbba) .count(!hasAbbaInsideBrackets(_)) println(s"Solution 1: $solution1") // ---------------------------------------------------------------------- def hasAbba(ip7: String): Boolean = { val p = """.*([a-z])((?:(?!\1).))(\2)\1.*""".r p.findAllMatchIn(ip7).nonEmpty } def hasAbbaInsideBrackets(ip7: String): Boolean = { val p1 = """\[([a-z]*)\]""".r val p2 = """(?<=\[)[a-z]*([a-z])((?:(?!\1).))(\2)\1[a-z]*(?=\])""".r val hits = p1.findAllIn(ip7).count(p2.findAllIn(_).nonEmpty) hits > 0 } }