Skip to content

Commit

Permalink
Update README and demo posts
Browse files Browse the repository at this point in the history
  • Loading branch information
EllaKaye committed Nov 29, 2023
1 parent 38fbf31 commit be7400a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 32 deletions.
7 changes: 3 additions & 4 deletions 2022/day/1/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ OK <- "2022" < 3000
# Will only evaluate next code block if an actual year has been substituted for the placeholder
```

::: {.callout-note}
This 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.
:::

```{r}
#| eval: !expr OK
Expand All @@ -30,10 +33,6 @@ input <- aoc_input_vector(1, 2022, "numeric")

I'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.

::: {.callout-note}
This 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.
:::

In this challenge, we're given groups of numbers and we need to find the sum of each group.
Our 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`.
We can identify the new groups by the `NA` values, produce an index for them with `cumsum(is.na(input))`,
Expand Down
8 changes: 0 additions & 8 deletions 2022/day/2022-intro/index.qmd

This file was deleted.

7 changes: 6 additions & 1 deletion 2023/day/2023-introduction/index.qmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
---
title: "2023: Introduction"
date: 2023-11-30
code-tools: false
---

This year, I'm planning to solve Advent of Code challenges using R and hope to learn how to ...
Here's a demo introduction page. It's created from `"./_templates/YYYY-intro"` as part of the call to `aoc_new_year(2023)`.

It can be deleted with a call to `aoc_delete_intro(2023)` (though there needs to be at least one post in `./2023/day` for the website to render from Quarto v1.4).

This is a good place to note any overarching themes for the year, what you want to practice/learn, etc.
12 changes: 6 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ output: github_document

# Advent of Code Website Template

Here's a template for making [Quarto](https://quarto.org) websites for working on and easy publishing [Advent of Code](https://adventofcode.com) solutions.
Here's a template for making [Quarto](https://quarto.org) websites for working on and (optionally) publishing [Advent of Code](https://adventofcode.com) solutions. Essentially, each year is a listing page, and each day is a post.

It works hand-in-hand with the [**aochelpers**](https://ellakaye.github.io/aochelpers) package for R,
which makes it incredibly easy to set up new posts and listings,
which makes it incredibly easy to set up new posts, scripts and listings,
using supplied (though personalisable) templates, found in the `_templates` directory.
When a template is copied by functions from **aochelpers**,
e.g. `aoc_new_year(2023)` or `aoc_new_day(1, 2023)`
any occurrence of "DD" and "YYYY" in both the template titles
e.g. `aoc_new_year(2022)` or `aoc_new_day(1, 2023)`
any occurrence of "DD" and "YYYY" in both the copied files' titles
and the text inside will be replaced with the value of the `day`
and `year` arguments respectively.

Expand Down Expand Up @@ -57,8 +57,8 @@ The calls used to create this template were:
```{r example}
#| eval: false
# Add a listing page a directory for a new year
aoc_new_year() # set up current year
aoc_new_year(2022) # set up specified year
aoc_new_year() # set up current year (including intro post)
aoc_new_year(2022, intro = FALSE) # set up a specified year (without intro post)
# Add a post for a new day
aoc_new_day(1, 2022) # day 1 of 2022 (don't need to specify year for current year)
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
# Advent of Code Website Template

Here’s a template for making [Quarto](https://quarto.org) websites for
working on and easy publishing [Advent of
Code](https://adventofcode.com) solutions.
working on and (optionally) publishing [Advent of
Code](https://adventofcode.com) solutions. Essentially, each year is a
listing page, and each day is a post.

It works hand-in-hand with the
[**aochelpers**](https://ellakaye.github.io/aochelpers) package for R,
which makes it incredibly easy to set up new posts and listings, using
supplied (though personalisable) templates, found in the `_templates`
directory. When a template is copied by functions from **aochelpers**,
e.g. `aoc_new_year(2023)` or `aoc_new_day(1, 2023)` any occurrence of
“DD” and “YYYY” in both the template titles and the text inside will be
replaced with the value of the `day` and `year` arguments respectively.
which makes it incredibly easy to set up new posts, scripts and
listings, using supplied (though personalisable) templates, found in the
`_templates` directory. When a template is copied by functions from
**aochelpers**, e.g. `aoc_new_year(2022)` or `aoc_new_day(1, 2023)` any
occurrence of “DD” and “YYYY” in both the copied files’ titles and the
text inside will be replaced with the value of the `day` and `year`
arguments respectively.

The website corresponding to this template is
<https://ellakaye.github.io/advent-of-code-website-template>, so you can
Expand Down Expand Up @@ -86,8 +88,8 @@ The calls used to create this template were:

``` r
# Add a listing page a directory for a new year
aoc_new_year() # set up current year
aoc_new_year(2022) # set up specified year
aoc_new_year() # set up current year (including intro post)
aoc_new_year(2022, intro = FALSE) # set up a specified year (without intro post)

# Add a post for a new day
aoc_new_day(1, 2022) # day 1 of 2022 (don't need to specify year for current year)
Expand Down
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": "ab9a5d8e0b76ce6b0d83703dac6bd095",
"hash": "0764578e0fb0cfd46503d3e0b170168f",
"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::: {.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\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\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.1 (2023-06-16)\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-15\n pandoc 3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)\n quarto 1.4.489 @ /usr/local/bin/quarto\n\n─ Packages ───────────────────────────────────────────────────────────────────\n package * version date (UTC) lib source\n aochelpers * 0.0.0.9000 2023-11-13 [1] local\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\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",
"supporting": [
"index_files"
],
Expand Down
2 changes: 1 addition & 1 deletion index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The package provides function to manage this website, e.g. to create new posts f
to download and read in the puzzle input,
and will eventually include functions to help with the challenges themselves. See the [package website](https://ellakaye.github.io/aochelpers/) for more details.

As part of the demo, this template comes with an example listing page and some example posts for 2022, which you can delete with `aochelpers::aoc_delete_year(2022)`, as well as a listing and introduction to get started for 2023.
As part of the demo, this template comes with an example listing page and Day 1 post for 2022, which you can delete with `aochelpers::aoc_delete_year(2022)`, as well as a listing and introduction to get started for 2023.

There are two built-in themes. The light theme is designed to be quite clean, with a Christmas green and red colours. The dark theme is designed to be reminiscent of the Advent of Code website (though not identical, since the design of <https://adventofcode.com> is part of its registered trademark). You can switch between them using the toggle in the top right corner of the page. Both themes use [fonts from iA](https://github.com/iaolo/iA-Fonts). The themes can be adapted in the `custom-light.scss` and `custom-dark.scss` files.

Expand Down

0 comments on commit be7400a

Please sign in to comment.