diff --git a/day_01.Rmd b/day_01.Rmd index ed5b686..0f453c1 100644 --- a/day_01.Rmd +++ b/day_01.Rmd @@ -4,6 +4,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL) library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 1](https://adventofcode.com/2020/day/1). @@ -247,3 +249,7 @@ def part_2_py(input_values, target): bench::mark(part_2_improved(actual, 2020), py$part_2_py(actual, 2020)) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_02.Rmd b/day_02.Rmd index fcb7ab4..5dcd292 100644 --- a/day_02.Rmd +++ b/day_02.Rmd @@ -4,6 +4,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL) library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 2](https://adventofcode.com/2020/day/2). @@ -126,3 +128,7 @@ This matches the example, so we can now solve part 2. ```{r part 2 solution} length(part_2_valid_passwords(actual)) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_03.Rmd b/day_03.Rmd index e590c6b..92ff3af 100644 --- a/day_03.Rmd +++ b/day_03.Rmd @@ -4,6 +4,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL) library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 3](https://adventofcode.com/2020/day/3). @@ -149,3 +151,7 @@ The other combinations would be going just 1 down at each step, and then all of that the greatest common divisor of right and down is 1. This would give us all of the movements that don't violate the constraint above of a non-unique movement. For instance, 6 right, 2 down has a greatest common divisor of 2, and this combination is the same as 3 right, 1 down. + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_04.Rmd b/day_04.Rmd index a80a87f..e383b1c 100644 --- a/day_04.Rmd +++ b/day_04.Rmd @@ -4,6 +4,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL) library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 4](https://adventofcode.com/2020/day/4). @@ -191,3 +193,7 @@ actual %>% map_lgl(compose(all, flatten_lgl)) %>% sum() ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_05.Rmd b/day_05.Rmd index 46ca8a5..831243d 100644 --- a/day_05.Rmd +++ b/day_05.Rmd @@ -4,6 +4,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL) library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 5](https://adventofcode.com/2020/day/5). @@ -110,3 +112,7 @@ triangle_number <- function(n) 0.5 * n * (n + 1) triangle_number(max(seats)) - triangle_number(min(seats) - 1) - sum(seats) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_06.Rmd b/day_06.Rmd index 7360e78..d788302 100644 --- a/day_06.Rmd +++ b/day_06.Rmd @@ -4,6 +4,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL) library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 6](https://adventofcode.com/2020/day/6). @@ -112,3 +114,7 @@ We can now check that this new function works as expected: extra(actual, union) == part_1(actual) extra(actual, intersect) == part_2(actual) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_07.Rmd b/day_07.Rmd index 493df33..70cd0c5 100644 --- a/day_07.Rmd +++ b/day_07.Rmd @@ -7,6 +7,8 @@ library(tidyverse) library(igraph) library(ggraph) library(unglue) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 7](https://adventofcode.com/2020/day/7). @@ -154,3 +156,7 @@ part_2_alt(sample_g, "shiny gold", 1) - 1 == part_2(sample_g) ```{r extra part 2 alt actual test} part_2_alt(actual_g, "shiny gold", 1) - 1 == part_2(actual_g) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_08.Rmd b/day_08.Rmd index bf4843f..615a353 100644 --- a/day_08.Rmd +++ b/day_08.Rmd @@ -6,6 +6,8 @@ options(crayon.enabled = NULL) library(tidyverse) library(R6) library(unglue) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 8](https://adventofcode.com/2020/day/8). @@ -321,3 +323,7 @@ Computer <- R6Class( ) ) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_09.Rmd b/day_09.Rmd index 7d102e2..44b92ce 100644 --- a/day_09.Rmd +++ b/day_09.Rmd @@ -4,6 +4,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL) library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 9](https://adventofcode.com/2020/day/9). @@ -89,3 +91,7 @@ And run on the actual input: ```{r part 2 sample actual} part_2(actual, pa1) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_10.Rmd b/day_10.Rmd index 1536c58..68fed17 100644 --- a/day_10.Rmd +++ b/day_10.Rmd @@ -4,6 +4,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL) library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 10](https://adventofcode.com/2020/day/10). @@ -86,3 +88,7 @@ notation by setting the `scipen` option. options(scipen = 999) part_2(actual) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_11.Rmd b/day_11.Rmd index 9761a79..335347d 100644 --- a/day_11.Rmd +++ b/day_11.Rmd @@ -4,6 +4,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL) library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 11](https://adventofcode.com/2020/day/11). @@ -386,3 +388,7 @@ solve(pactual, part_one, 4) solve(psample, part_two, 5) solve(pactual, part_two, 5) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_12.Rmd b/day_12.Rmd index ce1420e..25edef2 100644 --- a/day_12.Rmd +++ b/day_12.Rmd @@ -4,6 +4,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL) library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 12](https://adventofcode.com/2020/day/12). @@ -196,3 +198,7 @@ We can now run with the actual data: ```{r part 2 actual} solve(iactual) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_13.Rmd b/day_13.Rmd index aeb2613..2e9a1c9 100644 --- a/day_13.Rmd +++ b/day_13.Rmd @@ -4,6 +4,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL) library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 13](https://adventofcode.com/2020/day/13). @@ -98,3 +100,7 @@ the answer as an integer. options(scipen = 999) part_2(actual) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_14.Rmd b/day_14.Rmd index 7aa4ffc..7a8a8fc 100644 --- a/day_14.Rmd +++ b/day_14.Rmd @@ -6,6 +6,8 @@ options(crayon.enabled = NULL, # for when rendering on github actions scipen = 999) # make sure we never print in scientific notation library(tidyverse) library(unglue) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 14](https://adventofcode.com/2020/day/14). @@ -174,4 +176,6 @@ part_2(sample_2) == 208 part_2(actual) ``` +--- +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_15.Rmd b/day_15.Rmd index 5a771a5..5914c4d 100644 --- a/day_15.Rmd +++ b/day_15.Rmd @@ -5,6 +5,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL, # for when rendering on github actions scipen = 999) # make sure we never print in scientific notation library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 15](https://adventofcode.com/2020/day/15). @@ -71,3 +73,7 @@ We don't need to change anything for part 2, other than the number of turns. ```{r part 2} solve(actual, 30000000) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_16.Rmd b/day_16.Rmd index 2b90cc2..83f5995 100644 --- a/day_16.Rmd +++ b/day_16.Rmd @@ -6,6 +6,8 @@ options(crayon.enabled = NULL, # for when rendering on github actions scipen = 999) # make sure we never print in scientific notation library(tidyverse) library(unglue) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 16](https://adventofcode.com/2020/day/16). @@ -163,7 +165,7 @@ part_2(psample_2) And now we can solve the actual problem. Find the fields and their positions, the apply those positions to `my_ticket`: -```{r} +```{r part 2 actual} ps <- pactual %>% part_2() %>% filter(str_detect(field, "^departure")) %>% @@ -171,3 +173,7 @@ ps <- pactual %>% prod(pactual$my_ticket[ps]) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_17.Rmd b/day_17.Rmd index d109d0f..07a3262 100644 --- a/day_17.Rmd +++ b/day_17.Rmd @@ -6,6 +6,8 @@ options(crayon.enabled = NULL, # for when rendering on github actions scipen = 999) # make sure we never print in scientific notation library(tidyverse) library(unglue) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 17](https://adventofcode.com/2020/day/17). @@ -199,3 +201,7 @@ actual %>% run_n_iterations_4d(6) %>% sum() ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_18.Rmd b/day_18.Rmd index 99ee3b3..6d4de1a 100644 --- a/day_18.Rmd +++ b/day_18.Rmd @@ -7,6 +7,8 @@ options(crayon.enabled = NULL, # for when rendering on github actions library(tidyverse) library(unglue) library(R6) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 18](https://adventofcode.com/2020/day/18). @@ -195,3 +197,7 @@ And we can run the function on the actual data. ```{r part 2 actual} sum(part_2(actual)) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_19.Rmd b/day_19.Rmd index f9714b0..d474e1c 100644 --- a/day_19.Rmd +++ b/day_19.Rmd @@ -6,6 +6,8 @@ options(crayon.enabled = NULL, # for when rendering on github actions scipen = 999) # make sure we never print in scientific notation library(tidyverse) library(unglue) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 19](https://adventofcode.com/2020/day/19). @@ -172,3 +174,7 @@ part_2(part_2_sample) ```{r part 2 actual} part_2(actual) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_20.Rmd b/day_20.Rmd index 43b8523..e7c83da 100644 --- a/day_20.Rmd +++ b/day_20.Rmd @@ -5,6 +5,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL, # for when rendering on github actions scipen = 999) # make sure we never print in scientific notation library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 20](https://adventofcode.com/2020/day/20). @@ -371,3 +373,7 @@ part_2(actual) This felt rather tedious and procedural, perhaps there is a neater solution. Improvements could be made to my code by extracting some of the repeated logic into functions. + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_21.Rmd b/day_21.Rmd index 03cc8f5..b741618 100644 --- a/day_21.Rmd +++ b/day_21.Rmd @@ -6,6 +6,8 @@ options(crayon.enabled = NULL, # for when rendering on github actions scipen = 999) # make sure we never print in scientific notation library(tidyverse) library(igraph) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 21](https://adventofcode.com/2020/day/21). @@ -116,3 +118,7 @@ And we can run our function on the actual data: ```{r part 2 actual} part_2(actual) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_22.Rmd b/day_22.Rmd index bbb9490..ad2a3ac 100644 --- a/day_22.Rmd +++ b/day_22.Rmd @@ -5,6 +5,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL, # for when rendering on github actions scipen = 999) # make sure we never print in scientific notation library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 22](https://adventofcode.com/2020/day/22). @@ -175,3 +177,7 @@ And we can run this function on the actual data: ```{r part 2 actual} part_2(actual) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_23.Rmd b/day_23.Rmd index 13fbe95..33b76b4 100644 --- a/day_23.Rmd +++ b/day_23.Rmd @@ -5,6 +5,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL, # for when rendering on github actions scipen = 999) # make sure we never print in scientific notation library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 23](https://adventofcode.com/2020/day/23). @@ -129,3 +131,7 @@ And we can run the function on our actual data: ```{r part 2 actual} part_2(actual) ``` + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_24.Rmd b/day_24.Rmd index 8b992ac..e4b7a5d 100644 --- a/day_24.Rmd +++ b/day_24.Rmd @@ -5,6 +5,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL, # for when rendering on github actions scipen = 999) # make sure we never print in scientific notation library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 24](https://adventofcode.com/2020/day/24). @@ -148,3 +150,6 @@ And we can run this function on the actual data: part_2(actual, 100) ``` +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s* diff --git a/day_25.Rmd b/day_25.Rmd index f8e395f..15620d7 100644 --- a/day_25.Rmd +++ b/day_25.Rmd @@ -5,6 +5,8 @@ knitr::opts_chunk$set(echo = TRUE) options(crayon.enabled = NULL, # for when rendering on github actions scipen = 999) # make sure we never print in scientific notation library(tidyverse) + +START_TIME <- Sys.time() ``` This is my attempt to solve [Day 25](https://adventofcode.com/2020/day/25). @@ -96,3 +98,7 @@ find_key(actual[[3 - i]], actual_loops[[i]]) ## Part 2 We are done for 2020! Hopefully this has been a useful resource for you! + +--- + +*Elapsed Time: `r round(Sys.time() - START_TIME, 3)`s*