Advent of Code
1 Input Fetching
open-aoc-input
fetch-aoc-input
advent-day?
advent-year?
2 Automatic Submission
aoc-submit
aoc-submit*
3 Requests
aoc-session?
aoc-url
exn:  fail:  aoc
aoc-request
4 Meta and Environment Utilities
current-aoc-time
session-file
find-session
8.12

Advent of Code🔗ℹ

eutro

 (require advent-of-code) package: advent-of-code

A package for fetching Advent of Code input.

1 Input Fetching🔗ℹ

 (require advent-of-code/input) package: advent-of-code

procedure

(open-aoc-input session    
  year    
  day    
  [#:cache cache])  input-port?
  session : aoc-session?
  year : advent-year?
  day : advent-day?
  cache : (or/c boolean? path-string?) = #f
Fetch the puzzle input for day of year as an input port.

If you are using this in your puzzle solution, use of the cache argument is highly recommended.

See aoc-request for information on session, caching and error handling.

procedure

(fetch-aoc-input session    
  year    
  day    
  [#:cache cache])  string?
  session : aoc-session?
  year : advent-year?
  day : advent-day?
  cache : (or/c boolean? path-string?) = #f
Fetch the input data as a string, using open-aoc-input.

See open-aoc-input.

A day of the month between 1 and 25.

Equivalent to (integer-in 1 25).

A year since 2015.

Equivalent to (and/c exact-integer? (>=/c 2015)).

2 Automatic Submission🔗ℹ

 (require advent-of-code/answer) package: advent-of-code

This module also reprovides advent-year? and advent-day?

procedure

(aoc-submit session year day part answer)  string?

  session : aoc-session?
  year : advent-year?
  day : advent-day?
  part : (or/c 1 2)
  answer : any/c
Submit answer as an answer to the given puzzle.

answer will be formatted with display before being submitted.

Returns the string that the Advent of Code site returns, to be read by a human.

procedure

(aoc-submit* session year day part answer)  input-port?

  session : aoc-session?
  year : advent-year?
  day : advent-day?
  part : (or/c 1 2)
  answer : any/c
Like aoc-submit, but yields the full port containing the response to the request.

This is the HTML page that the site shows the user upon submitting an answer.

3 Requests🔗ℹ

 (require advent-of-code/request) package: advent-of-code

Procedures for making API requests. Reprovided by advent-of-code.

procedure

(aoc-session? x)  boolean?

  x : any/c
Predicate for an Advent of Code session cookie.

Equivalent to string?.

value

aoc-url : url?

struct

(struct exn:fail:aoc exn:fail (status)
    #:extra-constructor-name make-exn:fail:aoc)
  status : string?
Raised by aoc-request if a request fails.

procedure

(aoc-request session    
  path ...    
  [#:cache cache    
  #:post post?])  input-port?
  session : aoc-session?
  path : any/c
  cache : (or/c boolean? path-string?) = #f
  post? : (or/c #f bytes? string? input-port? payload-procedure/c)
   = #f
Makes an HTTP GET or POST request to the Advent of Code website, using the given session cookie.

If post? is supplied, then it is POST-ed as the payload, otherwise a simple GET request is made.

The cache argument specifies how the data should be cached.

Raises exn:fail:aoc if the request fails.

4 Meta and Environment Utilities🔗ℹ

 (require advent-of-code/meta) package: advent-of-code

Meta and environment functions. Reprovided by advent-of-code.

procedure

(current-aoc-time)  date?

The current EST (UTC-5) time, on which the Advent of Code calendar is based.

The path of the file used to fetch the current session by find-session.

procedure

(find-session)  aoc-session?

Attempt to find a valid aoc-session? for the user.

Tries to read session-file, if it is less than one month old, otherwise interactively prompts the user to enter the session cookie themselves, and saves it in session-file for later.

This is meant to be used by interactive programs, since it reads from current-input-port and writes to current-output-port.