Skip to contents

Get the puzzle input from the Advent of Code website for a given day and year and save it to a file. The file will be saved in the current working directory with a relative path "./YYYY/day/DD/input", where YYYY is the value of the year parameter and DD is value of the day parameter. This path echoes the URL structure of the Advent of Code website.

Usage

aoc_get_input(day, year = NULL)

Arguments

day

An integer between 1 and 25

year

An integer representing the year, from 2015 to the current year. Defaults to the current year.

Value

Returns, invisibly, a character string with the absolute path to the input file.

Details

This function assumes that you have an account on the Advent of Code website. For this function to work, you must set the ADVENT_SESSION environment variable in your .Renviron file. For guidance on how to find your session token, see https://github.com/dgrtwo/adventdrob/tree/main#installation. Once you have your session token, you can set the environment variable with usethis::edit_r_environ(). This function is adapted from https://github.com/dgrtwo/adventdrob/blob/main/R/input.R, but saves the input to a file instead of returning it as a data frame. Once the input is saved, it can be read in with aoc_input_vector(), aoc_input_data_frame() or aoc_input_matrix(), whichever is appropriate for the puzzle. This function is also called as part of aoc_new_day().

Examples

if (FALSE) aoc_get_input(1, 2022) # \dontrun{}