-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathday_23.ex
More file actions
44 lines (37 loc) · 999 Bytes
/
day_23.ex
File metadata and controls
44 lines (37 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
defmodule AdventOfCode.Y2024.Day23 do
@moduledoc """
--- Day 23: LAN Party ---
Problem Link: https://adventofcode.com/2024/day/23
Difficulty: m
Tags: bron-kerbosch clique graph lan-party maximum-clique
"""
alias AdventOfCode.Helpers.{InputReader, Transformers}
alias Yog.Property.Clique
def input, do: InputReader.read_from_file(2024, 23)
def run(input \\ input()) do
graph = parse(input)
p1 = solve_p1(graph)
p2 = solve_p2(graph)
{p1, p2}
end
defp solve_p1(graph) do
Clique.k_cliques(graph, 3)
|> Enum.count(fn clique ->
clique |> Enum.any?(&String.starts_with?(&1, "t"))
end)
end
defp solve_p2(graph) do
Clique.max_clique(graph)
|> MapSet.to_list()
|> Enum.sort()
|> Enum.join(",")
end
def parse(data \\ input()) do
data
|> Transformers.lines()
|> Enum.reduce(Yog.undirected(), fn line, graph ->
[u, v] = String.split(line, "-")
Yog.add_edge_ensure(graph, u, v, 1)
end)
end
end