knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

Advent of Code 2021

R-CMD-check

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)
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:

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.



Selbosh/adventofcode2021 documentation built on Jan. 1, 2022, 7:20 p.m.