Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions 2016/src/main/scala/aoc2016/Day07.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ object Day07 extends AoC:
def hasTLS: Boolean =
supernets.exists(_.sliding(4).exists(isAbba)) && !hypernets.exists(_.sliding(4).exists(isAbba))

private def isAba(s: String, containing: Option[(Char,Char)] = None): Option[(Char,Char)] =
private def isAba(s: String, containing: Option[(Char, Char)] = None): Option[(Char, Char)] =
containing match
case None =>
Option.when(s.length == 3 && s(0) != s(1) && s == s.reverse)((s(0), s(1)))
case Some((outer,inner)) =>
case Some((outer, inner)) =>
Option.when(s.length == 3 && s(0) != s(1) && s == s.reverse && s(0) == outer && s(1) == inner)((s(0), s(1)))

def hasSSL: Boolean =
Expand All @@ -34,12 +34,12 @@ object Day07 extends AoC:
def loop(todo: String, supernet: Boolean = true, supernets: Vector[String] = Vector.empty, hypernets: Vector[String] = Vector.empty): IP =
val chars = if supernet then todo.takeWhile(_ != '[') else todo.takeWhile(_ != ']')
val rest = todo.drop(chars.length + 1)
val nsupernets = if supernet then supernets :+ chars else supernets
val nhypernets = if !supernet then hypernets :+ chars else hypernets
val nextSupernets = if supernet then supernets :+ chars else supernets
val nextHypernets = if !supernet then hypernets :+ chars else hypernets
if rest.length > 1 then
loop(rest, !supernet, nsupernets, nhypernets)
loop(rest, !supernet, nextSupernets, nextHypernets)
else
IP(nsupernets, nhypernets)
IP(nextSupernets, nextHypernets)
loop(s)

val ips: Vector[IP] = lines.map(IP.fromString)
Expand Down