(<- scan(
stream_input here("DATA", "2022", "input_day_06.txt"),
what = "character"
%>%
) strsplit(split = "", fixed = TRUE) %>%
unlist()
%>% head(10) )
[1] "c" "v" "t" "v" "b" "v" "f" "b" "v" "f"
Julia Romanowska
This is the stream of characters that needs to be proceed in sequential manner to find the start-of-packet marker. This is indicated by a sequence where all four characters are different.
I will need to check at each item:
pop_first <- function(cur_read){
return(cur_read[-1])
}
push_last <- function(cur_read, new_char){
return(c(cur_read, new_char))
}
update_cur_read <- function(cur_read, new_char){
new_read <- pop_first(cur_read)
new_read <- push_last(new_read, new_char)
return(new_read)
}
check_uniqueness <- function(cur_read){
n_unique <- length(unique(cur_read))
return(n_unique == length(cur_read))
}
The number of characters to be processed before the first start-of-packet marker is detected is 1093! 🥳
The start-of-the-message marker consists of 14 distinct characters!
The number of characters to be processed before the first start-of-message marker is detected is 3534! 🥳