Skip to content

Instantly share code, notes, and snippets.

View day16.js
import _ = require("lodash")
let partAInput = "01110110101001000"
function flipItAndReverseIt(input: string): string {
return input.concat("0").concat((_.reverse(input.split(""))).map(x => x === "1" ? "0" : "1").join(""))
}
function fillDisk(input: string, size: number): string {
let data = input
while (data.length < size) {
View day15.js
import _ = require("lodash")
let input = `Disc #1 has 13 positions; at time=0, it is at position 11.
Disc #2 has 5 positions; at time=0, it is at position 0.
Disc #3 has 17 positions; at time=0, it is at position 11.
Disc #4 has 3 positions; at time=0, it is at position 0.
Disc #5 has 7 positions; at time=0, it is at position 2.
Disc #6 has 19 positions; at time=0, it is at position 17.`
interface Disc {
View day13.js
import crypto = require("crypto")
import _ = require("lodash")
let seed = "ahsbgdzn"
let useKeyStretching = true // part A / part B differentiator
let hashes: Object = {}
function getHash(i: number) {
if (hashes[i] === undefined) {
if (useKeyStretching) {
View day12.js
//------------------------------------------------
// Node console runner
import fs = require("fs")
import Global = require("./global")
import parse = require("./parse")
import run = require("./run")
const input = fs.readFileSync("./input.txt", "utf8")
const instructions = parse(input)
View day10.js
//=============================================
// Main - Node console runner
import fs = require("fs")
import Factory = require("./factory")
import parse = require("./parse")
const input = fs.readFileSync("./input.txt", "utf8")
const events = parse(input)
View day9.js
// DISCLAIMER:
//
// I'm getting lazier as I power through more and more of these Advent of Code challenges.
// Notably, I couldn't muster the energy to:
// * fix naming (e.g. part A is named "parseA" and part B is named "count")
// * Write part B tests
// * Write fine-grained unit tests
// * I probably left dead code in here
//
// Just know that I'm probably ashamed of some of this, but my laziness exceeds my fear of shame.
View day7.js
import fs = require("fs")
import color = require("cli-color")
enum IPNumberType {
Regular,
Hypernet
}
interface IPNumber {
type: IPNumberType,
View day6.js
//----------------------------------------------------
// main script
import fs = require("fs")
import _ = require("lodash")
import parse = require("./parse")
import decode = require("./decode")
const input = fs.readFileSync("./input.txt", "utf8")
const columns = parse(input)
const decoded = decode(columns)
View day4.js
/* test results:
PASS __tests__\day4.test.js
Acceptance tests
aaaaa-bbb-z-y-x-123[abxyz] is a real room (15ms)
totally-real-room-200[decoy] is not a real room
parsing
aaaaa-bbb-z-y-x-123[abxyz]
generating a checksum
aaaaa-bbb-z-y-x-123[abxyz]
decrypt
View day3.js
/* test results:
PASS __test__\day3.test.js
Acceptance tests
√ 5 10 25
√ 5 10 25, but not in any order of size
√ valid triangle 5 5 5
Vertical parsing
√ Input with wrong number of rows will throw an error (15ms)
√ Vertical triangles are parsed in groups of 3
*/