<- map(
levels_map readLines(
here("DATA", "2022", "input_day_12.txt")
),function(line){
str_split(line, pattern = "") %>% unlist()
}%>% do.call(rbind, .)
) dim(levels_map)
[1] 41 162
Julia Romanowska
Up, up, up, we are gonna climb!
The letters represent the levels, from a
(lowest) to z
(highest). We need to get from S
to E
(which is on level z
), but walking only one level up (or down) at a time.
levels_map <- map(
readLines(
here("DATA", "2022", "input_day_12.txt")
),
function(line){
str_split(line, pattern = "") %>% unlist()
}
) %>% do.call(rbind, .)
dim(levels_map)
[1] 41 162
levels_map %>%
as_tibble(rownames = "row") %>%
pivot_longer(cols = V1:V162, names_to = "col", values_to = "val") %>%
mutate(
col = as.numeric(str_sub(col, start = 2, end = -1)),
row = as.numeric(row),
val = factor(val, levels = c(letters, "E", "S"))
) %>%
ggplot(aes(col, row)) +
geom_tile(aes(fill = val)) +
coord_fixed() +
scale_fill_manual(
values = c(grey((1:length(letters))/length(letters)), "#0000FF", "#FF0000"),
name = ""
) +
theme_minimal() +
theme(
legend.position = "bottom",
legend.direction = "horizontal"
)
Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if
`.name_repair` is omitted as of tibble 2.0.0.
ℹ Using compatibility `.name_repair`.