Skip to content

Commit ff62e64

Browse files
committed
Solve 2024/23
1 parent 4586996 commit ff62e64

3 files changed

Lines changed: 3436 additions & 0 deletions

File tree

lib/2024/day_23.ex

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
defmodule AdventOfCode.Y2024.Day23 do
2+
@moduledoc """
3+
--- Day 23: LAN Party ---
4+
Problem Link: https://adventofcode.com/2024/day/23
5+
Difficulty: m
6+
Tags: graph clique bron-kerbosch maximum-clique LAN-party
7+
"""
8+
alias AdventOfCode.Helpers.{InputReader, Transformers}
9+
alias Yog.Property.Clique
10+
11+
def input, do: InputReader.read_from_file(2024, 23)
12+
13+
def run(input \\ input()) do
14+
graph = parse(input)
15+
16+
p1 = solve_p1(graph)
17+
p2 = solve_p2(graph)
18+
19+
{p1, p2}
20+
end
21+
22+
defp solve_p1(graph) do
23+
Clique.k_cliques(graph, 3)
24+
|> Enum.count(fn clique ->
25+
clique |> Enum.any?(&String.starts_with?(&1, "t"))
26+
end)
27+
end
28+
29+
defp solve_p2(graph) do
30+
Clique.max_clique(graph)
31+
|> MapSet.to_list()
32+
|> Enum.sort()
33+
|> Enum.join(",")
34+
end
35+
36+
def parse(data \\ input()) do
37+
data
38+
|> Transformers.lines()
39+
|> Enum.reduce(Yog.undirected(), fn line, graph ->
40+
[u, v] = String.split(line, "-")
41+
Yog.add_edge_ensure(graph, u, v, 1)
42+
end)
43+
end
44+
end

0 commit comments

Comments
 (0)