Skip to content

Latest commit

 

History

History
61 lines (54 loc) · 3.99 KB

File metadata and controls

61 lines (54 loc) · 3.99 KB

🎄 Advent of Code 2021 in R 🎄

This repository contains my solutions to the Advent of Code 2021 in R. My goal is to solve every puzzle using nothing else but base R functions and without any data frames or data frame manipulation functions (matrices, n-dimensional arrays and linear algebra operations are OK).

The "solutions as an R package" method is inspired by @tjmahr's approach to Advent of Code 2017. Briefly, each script under R/ contains the functions needed to solve the puzzle on a given day. Unit tests under tests/ verify that the solutions adhere to the requirements given by each puzzle specification, using the tiny testing data from the Advent of Code page for each day. Finally, inst/ contains small standalone R scripts which solve the full puzzles stored in text files under inst/extdata and print the results to the terminal. All of these solutions can be executed by a master script run-all.R.

Solutions

Why on Earth would you use R for this?

Several reasons. First, R is my favourite programming language. There, I said it.

Second, I spend nearly all time at my job doing data science—nearly everything I work with on a daily basis takes form of a (gigantic) table, and the purpose of my work is to produce figures, statistical models, and gain scientific insights. Advent of Code presents a very different class of problems that I rarely get to work with these days and it seemed like a fun challenge trying to solve them in R. Moreover, for an extra character building challenge, I decided to restrict myself to only use features available in base R without any additional packages and without using any data frames or functions that manipulate them (again, something that is very unusual when working with R).