-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
96 lines (77 loc) · 2.4 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# Advent of Code 2021
[![R-CMD-check](https://github.com/Selbosh/adventofcode2021/actions/workflows/r.yml/badge.svg)](https://github.com/Selbosh/adventofcode2021/actions)
_By [David Selby](https://selbydavid.com)_
This repository contains some of my attempts to solve programming puzzles in the [Advent of Code 2021](https://adventofcode.com/2021).
I will be mostly using the programming language R, with data and solutions presented as this downloadable R package.
## Installation
Install the package from GitHub with
```r
remotes::install_github('Selbosh/adventofcode2021')
```
## Development
Most puzzles in the Advent of Code include a few simple examples of input and expected output, before asking you to apply code to a larger dataset.
We can incorporate these into a _test-driven development_ framework by writing them as expectations in the `tests` folder.
Write a `test_that` expectation for each day, or part thereof, with these example inputs and outputs.
Then, we don't attempt to run our code on the main puzzle input until it generates the expected output for all of these tests.
## Usage
To print the numerical outputs, we can write vignettes, add our working to the GitHub `README.Rmd` file, or else write scripts in the `inst/` folder and to `source()` when required.
```{r day1, message = FALSE, fig.height = 2, fig.width = 8}
library(adventofcode2021)
get_solution(1)
get_solution(2)
get_solution(3)
get_solution(4)
get_solution(5)
get_solution(6)
get_solution(7)
get_solution(8)
get_solution(9)
get_solution(10)
get_solution(11)
get_solution(12)
get_solution(13)
get_solution(14)
get_solution(15)
get_solution(16)
get_solution(17)
```
From here they start taking a while to run, so here are some cached results:
```r
get_solution(18)
#> [1] 4008
#> [1] 4667
get_solution(19)
#> [1] 398
#> [1] 10965
get_solution(20)
#> [1] 5680
#> [1] 19766
get_solution(21)
#> [1] 412344
#> [1] "214924284932572"
get_solution(22)
#> [1] 591365
#> [1] "1211172281877240"
get_solution(23)
#> [1] 10411
#> [1] 46721
get_solution(24)
#> [1] "97919997299495"
#> [1] "51619131181131"
get_solution(25)
#> [1] 400
```
## Attribution
Puzzles and their descriptions are by Eric Wastl.