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 result = INPUT.reduce((total, _lwh) => { | |
const lwh = _lwh.split('x'); | |
const length = lwh[0]; | |
const width = lwh[1]; | |
const height = lwh[2]; | |
return total | |
+ (2 * length * width) |
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 result = INPUT.reduce((total, _lwh) => { | |
const lwh = _lwh.split('x').map(Number).sort((a, b) => a - b); | |
return total | |
+ (lwh[0] + lwh[0] + lwh[1] + lwh[1]) | |
+ (lwh[0] * lwh[1] * lwh[2]) | |
}, 0); |
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(''); | |
// Unique set of coordinates with the starting coordinates already added | |
const coordinates = new Set().add(`0x0`); | |
INPUT.reduce((curCoords, direction) => { | |
let newCoords = {x: 0, y: 0}; | |
if (direction === '^') newCoords = {x: curCoords.x, y: curCoords.y + 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(''); | |
const santaDirections = INPUT.filter((item, index) => index % 2 === 0); | |
const roboSantaDirections = INPUT.filter((item, index) => index % 2 === 1); | |
// Get array of directions and return array of visited coordinates | |
const traverse = directions => { | |
let visitedCoordinates = ['0x0']; | |
let currentPosition = {x: 0, y: 0}; |
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 crypto = require('crypto'); | |
const INPUT = 'ckczppom'; | |
const md5 = data => crypto.createHash('md5').update(data).digest('hex'); | |
const isStartsWithFiveZeros = data => data.slice(0, 5) === '00000'; | |
let counter = 0; | |
while (!isStartsWithFiveZeros(md5(`${INPUT}${counter}`))) counter++; | |
console.log(counter); |
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 crypto = require('crypto'); | |
const INPUT = 'ckczppom'; | |
const md5 = data => crypto.createHash('md5').update(data).digest('hex'); | |
const isStartsWithSixZeros = data => data.slice(0, 6) === '000000'; | |
let counter = 0; | |
while (!isStartsWithSixZeros(md5(`${INPUT}${counter}`))) counter++; | |
console.log(counter); |
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'); | |
// Dictionary of letters that need to be checked against the rules | |
const VOWELS = ['a', 'e', 'i', 'o', 'u']; | |
const DOUBLE_LETTERS = 'abcdefghijklmnopqrstuvwxyz'.split('').map(item => item + item); | |
const RESTRICTED_LETTERS = ['ab', 'cd', 'pq', 'xy']; | |
// Methods to check the rules | |
const isContainThreeVowels = string => string.split('').reduce((vowels, char) => VOWELS.indexOf(char) === -1 ? vowels : ++vowels, 0) >= 3; |
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'); | |
// Part 1 was written with pure functions but Part 2 I've decided to write with RegExp | |
const isContainPair = string => /([a-z][a-z]).*\1/.test(string); | |
const isContainRepeatLetter = string => /([a-z])[a-z]\1/.test(string); | |
const isNiceString = string => !!(isContainPair(string) && isContainRepeatLetter(string)); | |
const result = INPUT.reduce((total, string) => isNiceString(string) ? ++total : total, 0); |
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'); | |
// Parse command from string and return object | |
const parseCommand = _command => { | |
let command = _command.match(/(turn on|turn off|toggle) (\d+),(\d+) through (\d+),(\d+)/); | |
return {command: command[1], x1: +command[2], y1: +command[3], x2: +command[4], y2: +command[5]}; | |
}; | |
// Map of our lights |
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 COMMANDS_REGEX = /(turn on|turn off|toggle) (\d+),(\d+) through (\d+),(\d+)/; | |
// Parse command from string and return object | |
const parseCommand = _command => { | |
let command = _command.match(COMMANDS_REGEX); | |
return {command: command[1], x1: +command[2], y1: +command[3], x2: +command[4], y2: +command[5]}; | |
}; |