Created
December 25, 2023 05:53
-
-
Save tomjemmett/2307843ab2329246a0fb7bccdff4f438 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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