library(tidyverse)
library(unglue)
library(igraph)
Day 23
Advent of Code: Worked Solutions
Setup
Import libraries:
Read input from text file into a data frame:
<- read_lines("../input/day23.txt") |>
input unglue_data("{v1}-{v2}")
Part 1
Convert the lists of connections to an undirected graph:
<- input |>
g pmap(function(v1, v2) c(v1, v2)) |>
unlist() |>
make_graph(directed = FALSE)
Find all sets of 3 connected vertices (cliques of size 3) and count the sets having some vertex starting with ‘t’
cliques(g, min = 3, max = 3) |>
keep(
~ names(.x) |>
str_starts("t") |>
any()
|>
) length()
Part 2
Find the largest interconnected set of vertices, then convert the list of vertices into the “password” by sorting alphabetically and concatenating with commas:
|>
g largest_cliques() |>
unlist() |>
names() |>
sort() |>
str_flatten(",")