🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

@thefotios/advent_puzzle

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thefotios/advent_puzzle

Helper class for parsing and running Advent of Code puzzles

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

npm version

advent_puzzle

Simple helper class for parsing and running Advent of Code puzzles.

This will parse the data file in a few ways then call your processing function. Since each day has 2 puzzles (referred to here as A and B for simplicity), you can specify separate runners for each type.

Usage

  • Create a new Puzzle
const Puzzle = require('@thefotios/advent_puzzle');
const p = new Puzzle({
  // Each line is comma separated (with spaces)
  delimiter: /,\s+/,
  // Parse each element as an Integer
  numeric: true,
});
  • Define processors. These can also be passed into the constructor.

Valid Processors are run in the following order:

KeyWhen it's run
beforeAfter parsing the data, but before each puzzle
A or BRun depending on which puzzle is passed in the args
afterAfter the A or B processor is run
loggerLast, by default will console.log data
// Add elements of each line
p.A = lines => lines.map(data => data.reduce((acc, x) => acc + x, 0));

// Multiply elements of each line
p.B = lines => lines.map(data => data.reduce((acc, x) => acc * x, 1));

// Sort the results of each line (descending)
p.after = data => data.sort((a, b) => b - a);
  • Add run function

By default, this will run console.log on your final data

p.run()
  • Run it!
node your_script.js [data_file] [A or B]

Keywords

advent

FAQs

Package last updated on 06 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts