Skip to content

Instantly share code, notes, and snippets.

@tomjemmett
Created December 25, 2023 05:53
Show Gist options
  • Select an option

  • Save tomjemmett/2307843ab2329246a0fb7bccdff4f438 to your computer and use it in GitHub Desktop.

Select an option

Save tomjemmett/2307843ab2329246a0fb7bccdff4f438 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(igraph)
library(tidygraph)
library(ggraph)
input <- read_file("inputs/day25.txt") |>
stringr::str_trim() |>
str_split("\n") |>
pluck(1)
g <- input |>
str_split(": ") |>
map(\(.x) {
tibble(from = .x[[1]], to = stringr::str_split(.x[[2]], " ")[[1]])
}) |>
bind_rows() |>
graph_from_data_frame(directed = FALSE)
cut <- min_cut(g, value.only = FALSE)
length(cut$partition1) * length(cut$partition2)
ggraph(g) +
geom_edge_link() +
geom_node_label(aes(label = name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment