Share
Explore

Advent of Coda

Do fun coding challenges during the holidays!
The is a Christmas-themed, daily coding challenge that has been run each year since 2015. It’s a fun way to learn or sharpen your coding skills and have some fun during the holiday season.
You can complete the challenges using any programming language and environment you like, so why not a Coda Pack? This doc has everything you need to bootstrap your Pack and organize your solutions.
To get started,
Copy this doc
1️⃣ Pack code
When you copy the doc you’ll get a warning that the Advent of Code Pack is no longer available.
image.png
That’s expected, since you’ll need to create your own Pack with your solutions to the challenge. You can go ahead and remove it from the doc.
Use the code below to create your Pack. It provides the basic setup you’ll need to work with files and compute solutions.
import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();

pack.addNetworkDomain("codahosted.io");

pack.addFormula({
name: "ComputeSolution",
description: "Calculate the solution to a challenge.",
parameters: [
coda.makeParameter({
type: coda.ParameterType.String,
name: "challenge",
description: "Which challenge to compute.",
}),
coda.makeParameter({
type: coda.ParameterType.File,
name: "file",
description: "The file of input data.",
}),
],
resultType: coda.ValueType.String,
isAction: true,
execute: async function ([challenge, fileUrl], context) {
let func = Solutions[challenge];
if (!func) {
throw new coda.UserVisibleError("Unknown challenge: " + challenge);
}
let response = await context.fetcher.fetch({
method: "GET",
url: fileUrl,
});
let data = response.body;
let lines = data.split(/\r?\n/); if (lines[lines.length - 1] == "") {
lines.pop();
}
return String(func(lines));
},
});

// The list of solution functions you've written. Add them here and then
// refer to them in the Solution() formula above.
const Solutions = {
Day1A,
Day1B,
}

// Calculates the solution to the Day 1, Part 1.
function Day1A(lines) {
// TODO: Write the code.
return 0;
}

// Calculates the solution to the Day 1, Part 2.
function Day1B(lines) {
// TODO: Write the code.
return 0;
}
2️⃣ Table setup
3️⃣ Daily Challenge
Every day, for each part of the daily challenge:
Add a new function to the Pack. For example, function Day1A(lines) { ... }
Include the function in the Solutions constant.
Rebuild the Pack.
Add a row to the table below, entering the name of the function and uploading the input file.
Click the Compute button to run the function and get the output.
Enter the output into the Advent of Code website and see if you got it right!
Each participant is given a unique file for each challenge, so make sure to delete the example files for the Day 1 challenges in the table below.
Today's Challenge
Search
Challenge
Input
Run
Solution
Got it!
1
Day1A
input.txt
Compute
0
checkmark reaction, you have not reacted
2
Day1B
input.txt
Compute
0
checkmark reaction, you have not reacted
There are no rows in this table


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.