From be7400ab370f613adc8402c2d3c6015f356a9921 Mon Sep 17 00:00:00 2001 From: EllaKaye Date: Wed, 29 Nov 2023 14:22:55 +0000 Subject: [PATCH] Update README and demo posts --- 2022/day/1/index.qmd | 7 +++--- 2022/day/2022-intro/index.qmd | 8 ------- 2023/day/2023-introduction/index.qmd | 7 +++++- README.Rmd | 12 +++++----- README.md | 22 ++++++++++--------- .../day/1/index/execute-results/html.json | 4 ++-- index.qmd | 2 +- 7 files changed, 30 insertions(+), 32 deletions(-) delete mode 100644 2022/day/2022-intro/index.qmd diff --git a/2022/day/1/index.qmd b/2022/day/1/index.qmd index 0c6b4c3..be11f34 100644 --- a/2022/day/1/index.qmd +++ b/2022/day/1/index.qmd @@ -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 @@ -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))`, diff --git a/2022/day/2022-intro/index.qmd b/2022/day/2022-intro/index.qmd deleted file mode 100644 index 02f0e8c..0000000 --- a/2022/day/2022-intro/index.qmd +++ /dev/null @@ -1,8 +0,0 @@ ---- -title: "2022: Introduction" -date: 2022-11-30 ---- - -Here's a demo introduction page. It's created from `"./_templates/YYYY-intro"` as part of the call to `aoc_new_year(2022, intro = TRUE)`. - -This is a good place to note any over-riding themes for the year, what you want to practice/learn, etc. \ No newline at end of file diff --git a/2023/day/2023-introduction/index.qmd b/2023/day/2023-introduction/index.qmd index c019cf6..5b4a7e0 100644 --- a/2023/day/2023-introduction/index.qmd +++ b/2023/day/2023-introduction/index.qmd @@ -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 ... \ No newline at end of file +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. \ No newline at end of file diff --git a/README.Rmd b/README.Rmd index c49d07b..716e0db 100644 --- a/README.Rmd +++ b/README.Rmd @@ -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. @@ -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) diff --git a/README.md b/README.md index 130d7df..5fcfc73 100644 --- a/README.md +++ b/README.md @@ -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 , so you can @@ -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) diff --git a/_freeze/2022/day/1/index/execute-results/html.json b/_freeze/2022/day/1/index/execute-results/html.json index 130c2a5..7b10243 100644 --- a/_freeze/2022/day/1/index/execute-results/html.json +++ b/_freeze/2022/day/1/index/execute-results/html.json @@ -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
Toggle\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
\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
Toggle\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
\n\n\n\n\n\n", "supporting": [ "index_files" ], diff --git a/index.qmd b/index.qmd index a732c42..010a80e 100644 --- a/index.qmd +++ b/index.qmd @@ -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 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.