Skip to content

Commit

Permalink
Rmove appendix (closes #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
EllaKaye committed Dec 1, 2023
1 parent 32c5a63 commit f1cf563
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 62 deletions.
30 changes: 0 additions & 30 deletions 2022/day/1/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,3 @@ totals |>
sum()
```

##### 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>





4 changes: 2 additions & 2 deletions _freeze/2022/day/1/index/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"hash": "0764578e0fb0cfd46503d3e0b170168f",
"hash": "42c4d8ebbaabb2a53d0a564cde905089",
"result": {
"engine": "knitr",
"markdown": "---\ntitle: \"2022: Day 1\"\ndate: 2022-12-1\ncategories: [base R, lists]\ndraft: false\n---\n\n\n## Setup\n\n[The original challenge](https://adventofcode.com/2022/day/1)\n\n[My data](input){target=\"_blank\"}\n\n## Part 1\n\nI'm including this post in the website example to demonstrate what a typical post will look like, using `post-template`, in the `_templates` directory as a starting point. This post is created by a call to `aoc_new_day(1, 2022)`. It can be deleted with a call to `aoc_delete_day(1, 2022)`, or all posts and the listing for the year can be deleted with `aoc_delete_year(2022)`.\n\n\n::: {.cell}\n\n:::\n\n\n::: {.callout-note}\nThis is Ella Kaye's solution^[Ella is the author of this website template and of the **aochelpers** package, and the author of this demo post.], with her puzzle input. If attempting this challenge yourself, your solution will be different.\n:::\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(aochelpers)\ninput <- aoc_input_vector(1, 2022, \"numeric\")\n```\n:::\n\n\nI'm using the `aoc_input_vector()` function from the **aochelpers** package to read in the data, but otherwise using base R functions (including the native pipe, `|>`) for this puzzle. \n\nIn this challenge, we're given groups of numbers and we need to find the sum of each group. \nOur solution is the largest of these. The groups are separated by a blank line. When reading in the input as a numeric vector, these are coerced to `NA`.\nWe can identify the new groups by the `NA` values, produce an index for them with `cumsum(is.na(input))`,\nwhich increments when a new `NA` is reached, then use this with `split()` to split the input into a list of vectors, one for each group.\nWe need the argument `na.rm = TRUE` in `sapply()` because each vector, other than the first, starts with `NA`, as that's where it was split.\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntotals <- split(input, cumsum(is.na(input))) |> \n sapply(sum, na.rm = TRUE) \n\nmax(totals)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 66719\n```\n\n\n:::\n:::\n\n\n## Part 2\n\nThis is similar, except we want to find the sum of the sums of the top three groups.\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntotals |> \n sort() |> \n tail(3) |> \n sum()\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 198551\n```\n\n\n:::\n:::\n\n\n##### Session info {.appendix}\n\n<details><summary>Toggle</summary>\n\n\n::: {.cell}\n::: {.cell-output .cell-output-stdout}\n\n```\n─ Session info ───────────────────────────────────────────────────────────────\n setting value\n version R version 4.3.2 (2023-10-31)\n os macOS Sonoma 14.1\n system aarch64, darwin20\n ui X11\n language (EN)\n collate en_US.UTF-8\n ctype en_US.UTF-8\n tz Europe/London\n date 2023-11-29\n pandoc 3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)\n quarto 1.4.504 @ /usr/local/bin/quarto\n\n─ Packages ───────────────────────────────────────────────────────────────────\n package * version date (UTC) lib source\n aochelpers * 0.0.0.9000 2023-11-28 [1] Github (EllaKaye/aochelpers@58fe238)\n sessioninfo * 1.2.2 2021-12-06 [1] CRAN (R 4.3.0)\n\n [1] /Users/ellakaye/Library/R/arm64/4.3/library\n [2] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library\n\n──────────────────────────────────────────────────────────────────────────────\n```\n\n\n:::\n:::\n\n\n</details>\n\n\n\n\n\n",
"markdown": "---\ntitle: \"2022: Day 1\"\ndate: 2022-12-1\ncategories: [base R, lists]\ndraft: false\n---\n\n\n## Setup\n\n[The original challenge](https://adventofcode.com/2022/day/1)\n\n[My data](input){target=\"_blank\"}\n\n## Part 1\n\nI'm including this post in the website example to demonstrate what a typical post will look like, using `post-template`, in the `_templates` directory as a starting point. This post is created by a call to `aoc_new_day(1, 2022)`. It can be deleted with a call to `aoc_delete_day(1, 2022)`, or all posts and the listing for the year can be deleted with `aoc_delete_year(2022)`.\n\n\n::: {.cell}\n\n:::\n\n\n::: {.callout-note}\nThis is Ella Kaye's solution^[Ella is the author of this website template and of the **aochelpers** package, and the author of this demo post.], with her puzzle input. If attempting this challenge yourself, your solution will be different.\n:::\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(aochelpers)\ninput <- aoc_input_vector(1, 2022, \"numeric\")\n```\n:::\n\n\nI'm using the `aoc_input_vector()` function from the **aochelpers** package to read in the data, but otherwise using base R functions (including the native pipe, `|>`) for this puzzle. \n\nIn this challenge, we're given groups of numbers and we need to find the sum of each group. \nOur solution is the largest of these. The groups are separated by a blank line. When reading in the input as a numeric vector, these are coerced to `NA`.\nWe can identify the new groups by the `NA` values, produce an index for them with `cumsum(is.na(input))`,\nwhich increments when a new `NA` is reached, then use this with `split()` to split the input into a list of vectors, one for each group.\nWe need the argument `na.rm = TRUE` in `sapply()` because each vector, other than the first, starts with `NA`, as that's where it was split.\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntotals <- split(input, cumsum(is.na(input))) |> \n sapply(sum, na.rm = TRUE) \n\nmax(totals)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 66719\n```\n\n\n:::\n:::\n\n\n## Part 2\n\nThis is similar, except we want to find the sum of the sums of the top three groups.\n\n\n::: {.cell}\n\n```{.r .cell-code}\ntotals |> \n sort() |> \n tail(3) |> \n sum()\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 198551\n```\n\n\n:::\n:::\n",
"supporting": [
"index_files"
],
Expand Down
30 changes: 0 additions & 30 deletions _templates/post-template/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,3 @@ head(input)
## Part 2


##### 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>





0 comments on commit f1cf563

Please sign in to comment.