Last active
January 5, 2016 16:32
-
-
Save ghaiklor/f0daee9db2de8f353444 to your computer and use it in GitHub Desktop.
Advent of Code (Day 14 Part 1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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