Skip to content

Instantly share code, notes, and snippets.

Last active December 3, 2022 23:48
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Utility for loading the Advent of Code 2020 input into the Clojure REPL on demand
(ns pez.aoc2020.util
(:require [clj-http.client :as client]))
(defn fetch-input [day]
(let [cookie (slurp ".aoc-session")]
(:body (client/get
(str "" day "/input")
{:cookies {"session" {:value cookie}}})))
(catch Exception e
(println "Ho, ho, ho! Did you forget to populate `.aoc-session` with your AOC session cookie?")
(throw e))))
Copy link

PEZ commented Dec 2, 2020

This is a utility for fetching Advent of Code 2020 input data.

How to use:

In preparation. (The cookie lives for only 10 years, so you need to redo this in a decade):

  1. Be logged in at and open the problem page
  2. From Developer tools of the browser (Network tab), Copy the session cookie from the page resource (named just 2020 for index page).
  3. Store this in the file .aoc-session at the root of your project.

When trying to collect a star or two:

  1. Evaluate (util/fetch-input <day>) (probably into a def)

It looked like this in my Rich comment block for Day 2 (don't worry, no spoilers).

  (def input
    "1-3 a: abcde
1-3 b: cdefg
2-9 c: ccccccccc")
  (def input (util/fetch-input 2))
  (->> input
       (filter checks2?)
       (map :pwd)

I made do with the sample input until I thought my solution worked, then redefined input by fetching the problem input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment