Advent of Code 2023 -- A bootstrap article

Advent of Code is 25 days of coding problems, a kind of coding dojo with a daily exercise. You can use any language for any of the problems. The code isn't analyzed or shared.  Only the results count. I know people working in Python, Dart, Haskell, Rust, and C#. 

There are two problems per day, solved in order. The second problem only becomes visible once the first problem is solved. Each problem is driven by an input data set customized to your login session. The solution is often a number or some other small piece of data.   You won't be able to copy someone else's answer.

Any scoring or tracking is up to you. You can create your own team leader board or just do the problems without tracking against anyone else.

The problem workflow is

  1. Go to the website to read today's problem.
  2. Request today's input data set using your session cookie
  3. Write some code to generate a result
  4. Post the result into to today's page
  5. Earn stars and accolades.

Show me!  Don't make me read stuff

Sign Up

Sign up at https://adventofcode.com.  This login session will stay active for the life of the 25-day exercise.  Your session cookie is live for that full-time and can be programmatically used to get the input data and post your solution.  


You can sign up even if the event has already started.  There is no penalty for joining late other than ranking on the leader board which you may not care about anyway.

Finding your session cookie

Your session cookie is live for that full-time and can be programmatically used to get the input data and post your solution.  The cookie is part of every programmatic action.  

Inspect the Advent of Code web page using your browser inspect capability. The basic startup workflow is





  1. Open your browser to the Advent of Code web page.
  2. Right mouse and select inspect.
  3. This should pull up the inspector panel
  4. Refresh the page to populate the Network panel
  5. Select the home page request, "2023" in this picture.
  6. Select Network in the browser inspector's top pane
  7. Select Headers in the browser inspector's bottom pane.
  8. Find the header called session
  9. Copy the value of that header.  You will need it to get access to your data sets.


Start coding

From Scratch

You can just download your input data set to your machine and then start hacking code.  

With a Template in your language of choice

A lot of people will use a template so that they can create a fresh working file every day for that day's problem. The template retrieves that day's data, writes the data to a file and generates a shell program for that day.  People like the templates because they may have basic data manipulation dependencies already included along with helper methods.

I am using a template for Dart that I Forked on GitHub. Some 2023 work is in the 2023 branch. It is a Fork of this Dart Template on GitHub. The template manages new Day-xx.dart files with hooks for timers and other metrics. You should be able to find a template in the language of your choice if you exercise your Google-Fu.

Problems appear

Problems appear at fixed intervals, currently midnight ET.  The interface is minimal. You will only see the title page if the problem isn't ready yet.

Looking at a Problem

Problems appear under the current year. 

1. Click on the year in the upper left corner
1. You should see the number "1" or other day in the bottom right corner. Those are hyperlinks to that day's problems.
1. The highest number page may have a timer running.  That is how long it will be until the next problem becomes available.



The problem definition

You can see the problem definition page once you click on that day's link.  The picture to the right is a Day-1 problem.

There are two problems per day.  The 2nd problem only appears once the first problem is completed.

Problems include a problem definition and backstory along with a tiny sample data set and the solution to that problem for that tiny dataset.

The problem to the right accepts a single number as the result. 

The 2nd problem space is formatted the same way as the first. It appears when the first problem is completed.  


Retrieving the Data - a Sample

You can use Curl or your programming language of choice to download an input data set.  I decided to use a template that included code that downloads the sample to be used while writing code and testing.

This is a snippet of Dart code that downloads the input.  You can see that it has a very regular URL and expects the session cookie that we looked at above.

    final request = await HttpClient().getUrl(
      Uri.parse(
        'https://adventofcode.com/$year/day/${int.parse(dayNumber)}/input',
      ),
    );
    request.cookies.add(Cookie('session', session));

On Reddit


Revision History

Created 2023 11






Comments

Popular posts from this blog

Understanding your WSL2 RAM and swap - Changing the default 50%-25%

Installing the RNDIS driver on Windows 11 to use USB Raspberry Pi as network attached

DNS for Azure Point to Site (P2S) VPN - getting the internal IPs