Attaching package: 'rlang'
The following objects are masked from 'package:purrr':
%@%, as_function, flatten, flatten_chr, flatten_dbl, flatten_int,
flatten_lgl, flatten_raw, invoke, splice
Attaching package: 'scales'
The following object is masked from 'package:purrr':
discard
The following object is masked from 'package:readr':
col_factor
library(ggforce)library(emojifont)font_add_google(name ="Mountains of Christmas", family ="christmas")font_add(family ="Noto Emoji", regular =file.path(font_paths()[2], "NotoEmoji-VariableFont_wght.ttf"))showtext_auto()theme_set(theme_no_axes(base.theme =dark_theme_gray()) +theme(title =element_text(family ="christmas", size =20)))
Inverted geom defaults of fill and color/colour.
To change them back, use invert_geom_defaults().
knitr::knit_hooks$set(crop = knitr::hook_pdfcrop)
trees <-read_table("2022-12-8_assets/input.txt", col_names = F)
I think if I was cleverer I could use some kind of convolution…
grad_max <-function(x, dir =1){if(dir ==1){map(1:length(x), ~max(x[1:.x])) |>simplify() -> out }else{map(1:length(x), ~max(x[.x:length(x)])) |>simplify() -> out }return(out)}rev_diff <-function(x){ out <- x |>rev() |>diff() |>rev()return(out)}
l_to_r <-apply(tree_mat, 1, grad_max) |>t()r_to_l <-apply(tree_mat, 1, grad_max, dir =-1) |>t()t_to_b <-apply(tree_mat, 2, grad_max)b_to_t <-apply(tree_mat, 2, grad_max, dir =-1)
Ok, I spend a lot of time over thinking this. The visible trees are visible wherever this increasing max goes up. I’ll work that out for all 4 matrices (1 where visible, 0 otherwise) and just add them together. Any location >0 will be visible.