Skip to content

Instantly share code, notes, and snippets.

@ghaiklor
Last active January 5, 2016 16:32
Show Gist options
  • Save ghaiklor/f0daee9db2de8f353444 to your computer and use it in GitHub Desktop.
Save ghaiklor/f0daee9db2de8f353444 to your computer and use it in GitHub Desktop.
Advent of Code (Day 14 Part 1)
const fs = require('fs');
const INPUT = fs.readFileSync('./input.txt', 'utf-8').split('\n');
const REINDEER_REGEX = /\d+/g;
const TIME = 2503;
// It can be calculated by formula without cycling it in some kind of loop
const getReindeerDistance = input => {
const args = input.match(REINDEER_REGEX).map(Number);
const speed = args[0];
const time = args[1];
const rest = args[2];
return Math.ceil(TIME / (time + rest)) * (speed * time);
};
const result = INPUT.reduce((max, reindeer) => getReindeerDistance(reindeer) > max ? getReindeerDistance(reindeer) : max, 0);
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment