Skip to content

Commit

Permalink
Clean up 2024 day 23
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Dec 23, 2024
1 parent c2d2f77 commit 9c202dd
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/main/scala/eu/sim642/adventofcode2024/Day23.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ object Day23 {
type Computer = String
type Edge = (Computer, Computer)

def find3Cliques(edges: Set[Edge]): Set[Set[Computer]] = {
val neighbors = (edges ++ edges.map(_.swap)).groupMap(_._1)(_._2)
def edges2neighbors(edges: Set[Edge]): Map[Computer, Set[Computer]] =
(edges ++ edges.map(_.swap)).groupMap(_._1)(_._2)

def find3Cliques(edges: Set[Edge]): Set[Set[Computer]] = {
val neighbors = edges2neighbors(edges)
for {
(from, to) <- edges
third <- neighbors(from) & neighbors(to)
Expand All @@ -18,15 +20,11 @@ object Day23 {

def count3CliquesT(edges: Set[Edge]): Int = find3Cliques(edges).count(_.exists(_.startsWith("t")))

def maximumClique(edges: Set[Edge]): Set[Computer] = {
val neighbors = (edges ++ edges.map(_.swap)).groupMap(_._1)(_._2)
BronKerbosch.maximumClique(neighbors)
}
def maximumClique(edges: Set[Edge]): Set[Computer] =
BronKerbosch.maximumClique(edges2neighbors(edges))

def lanPartyPassword(edges: Set[Edge]): String = {
val clique = maximumClique(edges)
clique.toSeq.sorted.mkString(",")
}
def lanPartyPassword(edges: Set[Edge]): String =
maximumClique(edges).toSeq.sorted.mkString(",")

def parseEdge(s: String): Edge = s match {
case s"$from-$to" => (from, to)
Expand Down

0 comments on commit 9c202dd

Please sign in to comment.