Adventofcode2021
Solutions to Advent of Code 2021, written as a package in the R programming language.
Install / Use
/learn @Selbosh/Adventofcode2021README
Advent of Code 2021
By David Selby
This repository contains some of my attempts to solve programming puzzles in the Advent of Code 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
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.
library(adventofcode2021)
get_solution(1)
#> [1] 1266
#> [1] 1217
get_solution(2)
#> [1] 1746616
#> [1] 1741971043
get_solution(3)
#> [1] 4191876
#> [1] 3414905
get_solution(4)
#> [1] 64084
#> [1] 12833
get_solution(5)
#> [1] 5167
#> [1] 17604
get_solution(6)
#> [1] 391888
#> [1] "1754597645339"
get_solution(7)
#> [1] 356922
#> [1] 100347031
get_solution(8)
#> [1] 321
#> [1] 1028926
get_solution(9)
#> [1] 560
#> [1] 959136
get_solution(10)
#> [1] 394647
#> [1] 2380061249
get_solution(11)
#> [1] 1688
#> [1] 403
get_solution(12)
#> [1] 3292
#> [1] 89592
get_solution(13)
#> [1] 671
<img src="man/figures/README-day1-1.png" width="100%" />
get_solution(14)
#> [1] 2947
#> [1] "3232426226464"
get_solution(15)
#> [1] 388
#> [1] 2819
get_solution(16)
#> [1] 886
#> [1] 184487454837
get_solution(17)
#> [1] 9180
#> [1] 3767
From here they start taking a while to run, so here are some cached results:
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.
Related Skills
node-connect
340.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
340.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.2kCommit, push, and open a PR
