Toggle the code
library(aochelpers)
<- aoc_input_vector(6, 2022) input
Ella Kaye
December 6, 2022
─ Session info ───────────────────────────────────────────────────────────────
setting value
version R version 4.3.1 (2023-06-16)
os macOS Sonoma 14.1
system aarch64, darwin20
ui X11
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz Europe/London
date 2023-11-18
pandoc 3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
quarto 1.4.504 @ /usr/local/bin/quarto
─ Packages ───────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
aochelpers * 0.0.0.9000 2023-11-17 [1] local
sessioninfo * 1.2.2 2021-12-06 [1] CRAN (R 4.3.0)
[1] /Users/ellakaye/Library/R/arm64/4.3/library
[2] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
──────────────────────────────────────────────────────────────────────────────
---
title: "2022: Day 6"
date: 2022-12-6
author:
- name: Ella Kaye
categories: [base R, strings, loops]
draft: false
---
## Setup
[The original challenge](https://adventofcode.com/2022/day/6)
[My data](input){target="_blank"}
## Part 1
```{r}
#| echo: false
OK <- "2022" < 3000
# Will only evaluate next code block if an actual year has been substituted for the placeholder
```
```{r}
#| eval: !expr OK
library(aochelpers)
input <- aoc_input_vector(6, 2022)
```
```{r}
data <- strsplit(input, "") |> unlist()
for (i in 4:length(data)) {
last_4 <- data[(i-3):i]
last_4_unique <- last_4 |> unique() |> length()
if (last_4_unique == 4) {
break
}
}
i
```
## Part 2
```{r}
for (i in 14:length(data)) {
last_14 <- data[(i-13):i]
last_14_unique <- last_14 |> unique() |> length()
if (last_14_unique == 14) {
break
}
}
i
```
##### Session info {.appendix}
<details><summary>Toggle</summary>
```{r}
#| echo: false
library(sessioninfo)
# save the session info as an object
pkg_session <- session_info(pkgs = "attached")
# get the quarto version
quarto_version <- system("quarto --version", intern = TRUE)
# inject the quarto info
pkg_session$platform$quarto <- paste(
system("quarto --version", intern = TRUE),
"@",
quarto::quarto_path()
)
# print it out
pkg_session
```
</details>