Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2018/day-01/part-1/chronalCalibrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const parseData = require('../../inputParser').parseData
* @param {String} input list of values
*/
const chronalCalibrator = (input) => {
let adjustments = parseData(input)
const adjustments = parseData(input)
return adjustments.reduce(
(total, current) => total + current
)
Expand Down
8 changes: 4 additions & 4 deletions 2018/day-01/part-1/chronalCalibrator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ describe('--- Day 1: Chronal Calibration ---', () => {
it('should add a list frequency values', () => {
const sequence = '+1, +1, +1'
const expected = 3
let actual = chronalCalibrator(sequence)
const actual = chronalCalibrator(sequence)
expect(actual).to.equal(expected)
})

it('should subtract a list frequency values', () => {
const sequence = '-1, -2, -3'
const expected = -6
let actual = chronalCalibrator(sequence)
const actual = chronalCalibrator(sequence)
expect(actual).to.equal(expected)
})

it('should add a add and subtract a mixed list of frequency values', () => {
const sequence = '+1, +1, -2'
const expected = 0
let actual = chronalCalibrator(sequence)
const actual = chronalCalibrator(sequence)
expect(actual).to.equal(expected)
})

Expand All @@ -31,7 +31,7 @@ describe('--- Day 1: Chronal Calibration ---', () => {
+1
-2`
const expected = 0
let actual = chronalCalibrator(sequence)
const actual = chronalCalibrator(sequence)
expect(actual).to.equal(expected)
})
})
Expand Down
2 changes: 1 addition & 1 deletion 2018/day-01/part-1/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ const filePath = path.join(__dirname, '../input.txt')

fs.readFile(filePath, { encoding: 'utf8' }, (err, data) => {
if (err) throw err
let answer = chronalCalibrator(data)
const answer = chronalCalibrator(data)
console.log(`Answer: ${answer}`)
})
4 changes: 2 additions & 2 deletions 2018/day-01/part-2/chronalCalibrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const parseData = require('../../inputParser').parseData
* @param {String} input list of values
*/
function getFrequency (input) {
let adjustments = parseData(input)
const adjustments = parseData(input)
return adjustments.reduce(
(total, current) => total + current
)
Expand All @@ -19,7 +19,7 @@ function getFirstMatch (input) {
const sequence = parseData(input)
let freq = 0
let idx = 0
let log = [freq]
const log = [freq]
let matched = null
do {
// Adjust Frequence
Expand Down
8 changes: 4 additions & 4 deletions 2018/day-01/part-2/chronalCalibrator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ describe('--- Day 1: Chronal Calibration ---', () => {
it('finds the first frequency that is reached twice in test set 1', () => {
const sequence = '+1, -1'
const expected = 0
let actual = chronalCalibrator.getFirstMatch(sequence)
const actual = chronalCalibrator.getFirstMatch(sequence)
expect(actual).to.equal(expected)
})

it('finds the first frequency that is reached twice in test set 2', () => {
const sequence = '+3, +3, +4, -2, -4'
const expected = 10
let actual = chronalCalibrator.getFirstMatch(sequence)
const actual = chronalCalibrator.getFirstMatch(sequence)
expect(actual).to.equal(expected)
})

it('finds the first frequency that is reached twice in test set 3', () => {
const sequence = '-6, +3, +8, +5, -6'
const expected = 5
let actual = chronalCalibrator.getFirstMatch(sequence)
const actual = chronalCalibrator.getFirstMatch(sequence)
expect(actual).to.equal(expected)
})

it('finds the first frequency that is reached twice in test set 4', () => {
const sequence = '+7, +7, -2, -7, -4'
const expected = 14
let actual = chronalCalibrator.getFirstMatch(sequence)
const actual = chronalCalibrator.getFirstMatch(sequence)
expect(actual).to.equal(expected)
})
})
Expand Down
2 changes: 1 addition & 1 deletion 2018/day-01/part-2/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ const filePath = path.join(__dirname, '../input.txt')

fs.readFile(filePath, { encoding: 'utf8' }, (err, data) => {
if (err) throw err
let answer = chronalCalibrator.getFirstMatch(data)
const answer = chronalCalibrator.getFirstMatch(data)
console.log(`Answer: ${answer}`)
})
12 changes: 6 additions & 6 deletions 2018/day-02/boxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const unique = require('../helpers').unique
const hasNRepeatedChars = (haystack, n) => {
let chars = unique(haystack.split(''))
chars = chars.filter((char) => {
let needle = new RegExp(char, 'g')
let count = (haystack.match(needle) || []).length // find number of results in the ID
const needle = new RegExp(char, 'g')
const count = (haystack.match(needle) || []).length // find number of results in the ID
return (count === n)
})
return (chars.length > 0)
Expand All @@ -30,7 +30,7 @@ function getChecksum (input) {
* @returns {number}
*/
const scoreIDs = (str1, str2) => {
let common = getCommonLetters(str1, str2)
const common = getCommonLetters(str1, str2)
return str1.length - common.length
}

Expand All @@ -56,14 +56,14 @@ const getCommonLetters = (str1, str2) => {
* @returns {Array} list of similar IDs
*/
const findSimilarIDs = (ids, threshold) => {
let results = []
const results = []
threshold = threshold || 1

let searchIdx = 0
do {
let needle = ids[searchIdx]
const needle = ids[searchIdx]
// Find matches that differ by only one letter
let matches = ids.filter((id, idx) => {
const matches = ids.filter((id, idx) => {
// Don't repeat comparisons and don't compare to self
if (searchIdx <= idx) {
return false
Expand Down
8 changes: 4 additions & 4 deletions 2018/day-02/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const filePath = path.join(__dirname, 'input.txt')

fs.readFile(filePath, { encoding: 'utf8' }, (err, data) => {
if (err) throw err
let answer = boxes.getChecksum(data)
const answer = boxes.getChecksum(data)
console.log(`-- Part 1 --`)
console.log(`Answer: ${answer}`)

let ids = boxes.getListFromData(data)
let similar = boxes.findSimilarIDs(ids)
let answer2 = boxes.getCommonLetters(similar[0], similar[1])
const ids = boxes.getListFromData(data)
const similar = boxes.findSimilarIDs(ids)
const answer2 = boxes.getCommonLetters(similar[0], similar[1])
console.log(`-- Part 2 --`)
console.log(`Answer: ${answer2}`)
})
2 changes: 1 addition & 1 deletion 2018/day-03/claims.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const makeClaim = (claim) => {
* @returns {Object} Claim object with named properties
*/
const parseClaim = (str) => {
let claim = {}
const claim = {}
let vals = str.split(' @ ')
claim.id = vals[0].replace(/#/g, '')
vals = vals[1].split(',')
Expand Down
8 changes: 4 additions & 4 deletions 2018/day-03/claims.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ describe('--- Day 3: No Matter How You Slice It ---', () => {
describe('makeClaim(claim)', () => {
it('marks the points on the cloth with the claim ID', () => {
const claim = parseClaim(claims[0])
let result = makeClaim(claim)
const result = makeClaim(claim)
expect(result[1][1]).to.equal(undefined)
expect(result[3][2]).to.deep.equal([123])
expect(result[7][5]).to.deep.equal([123])
})

it('marks the points that are overlapped', () => {
let testClaims = claims.map(parseClaim)
const testClaims = claims.map(parseClaim)
let result = _cloth
for (let x = 1; x < claims.length; x++) {
result = makeClaim(testClaims[x])
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('--- Day 3: No Matter How You Slice It ---', () => {

describe('countConflicts()', () => {
it('counts the number of points with conflicting claims', () => {
let testClaims = claims.map(parseClaim)
const testClaims = claims.map(parseClaim)
for (let x = 1; x < claims.length; x++) {
makeClaim(testClaims[x])
}
Expand All @@ -105,7 +105,7 @@ describe('--- Day 3: No Matter How You Slice It ---', () => {
describe('Part 2', () => {
describe('findNonOverlappingClaims()', () => {
it('locates the first claim that doesn\'t have overlapping claims', () => {
let testClaims = claims.map(parseClaim)
const testClaims = claims.map(parseClaim)
for (let x = 1; x < claims.length; x++) {
makeClaim(testClaims[x])
}
Expand Down
20 changes: 10 additions & 10 deletions 2018/day-04/guards.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const helpers = require('./helpers')

let _data = {}
const _data = {}

const getData = (key) => _data[key]
const setData = (key) => _data[key]
Expand All @@ -12,7 +12,7 @@ const setData = (key) => _data[key]
const findLaziestGuards = (days) => {
// Get a list of guards with their sleeping times
// returns { id: XX, asleep: YY }
let guards = days.filter((day, idx, arr) => {
const guards = days.filter((day, idx, arr) => {
return (arr.indexOf(day) === idx) // filters a list of unique guard IDs
}).map((day) => {
return { id: day.guard } // Makes a list of guard objects
Expand Down Expand Up @@ -49,10 +49,10 @@ const findSleepiestTimes = (guard, data) => {
.map((minute) => minute.id) // convert into a list of times
}

let times = data.filter((day) => day.guard === guard) // Find the days the guard is working
const times = data.filter((day) => day.guard === guard) // Find the days the guard is working
.map((day) => getTimesAsleep(day.activity)) // Convert activity streams into lists of times where guard is asleep
.reduce((acc, day) => {
let counter = acc || []
const counter = acc || []
// Loop through the minutes of the day, and increment status in the acclumator if the guard is asleep
day.forEach((minute) => {
counter[minute] = (counter[minute]) ? counter[minute] + 1 : 1
Expand All @@ -75,7 +75,7 @@ const processActivities = (data) => {
}

// store variables iterated through the loop
let store = {
const store = {
date: data[0].date,
hour: data[0].hour,
minute: data[0].minute,
Expand All @@ -84,7 +84,7 @@ const processActivities = (data) => {
}

// Build up the results set
let results = [{
const results = [{
date: store.date,
guard: store.guard,
activity: ''
Expand All @@ -95,15 +95,15 @@ const processActivities = (data) => {
// Crossed into new day
if (event.date !== store.date) {
// Finish out the open pattern
let prevAct = results[results.length - 1].activity
const prevAct = results[results.length - 1].activity
if (prevAct.length < 60) {
results[results.length - 1].activity += store.state.repeat(60 - prevAct.length)
}

// Start a new activity pattern
// The new activity pattern should fill up to the current minute, or completely fill
// when the new event is in a later hour
let len = (event.hour === 0) ? event.minute : 60
const len = (event.hour === 0) ? event.minute : 60
results.push({
date: event.date,
guard: event.guard || store.guard,
Expand All @@ -113,10 +113,10 @@ const processActivities = (data) => {

// Event is the same day as the previous event
if (event.date === store.date) {
let act = results[results.length - 1].activity
const act = results[results.length - 1].activity
// Populate the previous state up to the current minute or up to the full hour
// when it's no longer the 0 hour
let len = (event.hour === 0) ? event.minute - act.length : 60 - act.length
const len = (event.hour === 0) ? event.minute - act.length : 60 - act.length

if (len > 0 && len < 60) {
results[results.length - 1].activity += store.state.repeat(len)
Expand Down
6 changes: 3 additions & 3 deletions 2018/day-04/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const dynamicSortMultiple = (...keys) => {
return (a, b) => {
let i = 0
let result = 0
let numberOfProperties = keys.length
const numberOfProperties = keys.length

while (result === 0 && i < numberOfProperties) {
result = dynamicSort(keys[i])(a, b)
Expand All @@ -67,8 +67,8 @@ const parseLog = (log) => {
* @returns {Object} { activity, date, guard, minute }
*/
const parseLogEntry = (entry) => {
let data = {}
let res = entry.split(' ')
const data = {}
const res = entry.split(' ')

data.date = res.shift()
.replace('[', '') // strip brackets from date
Expand Down
2 changes: 1 addition & 1 deletion 2018/day-04/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const init = (data) => {
// Sort the guards most likely to fall asleep on a repeated minute
guardsBySleepTime = guardsBySleepTime.map((guard) => {
if (guard.asleep > 0) {
let sleepiestTimes = findSleepiestTimes(guard.id, data)
const sleepiestTimes = findSleepiestTimes(guard.id, data)
guard.sleepiestMinute = sleepiestTimes[0].minute
guard.sleepiestMinuteQty = sleepiestTimes[0].qty
} else {
Expand Down
2 changes: 1 addition & 1 deletion 2018/day-05/polymer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const toggleCase = (input) => {
* @param {String} input Polymer chain
*/
const reducePolymer = (input) => {
let polymer = input.trim().split('')
const polymer = input.trim().split('')

polymer.forEach((char, idx) => {
if (toggleCase(char) === polymer[idx - 1]) {
Expand Down
2 changes: 1 addition & 1 deletion 2018/day-05/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fs.readFile(filePath, { encoding: 'utf8' }, (err, data) => {

data = data.trim()

let answer = reducePolymer(data).length
const answer = reducePolymer(data).length

// Try removing each potential problem pair, and see which gets to the smallest polymer
let answer2 = answer
Expand Down
10 changes: 5 additions & 5 deletions 2018/day-06/coordinates.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { dynamicSort } = require('../day-04/helpers')

let minX = 0
let minY = 0
const minX = 0
const minY = 0
let maxX = 10
let maxY = 10

Expand Down Expand Up @@ -30,15 +30,15 @@ const distance = (A, B) => {
* @param {*} data List of points to measure to
*/
const findClosestPoint = (source, data) => {
let distances = data.map((target, idx) => {
const distances = data.map((target, idx) => {
return {
id: idx,
distance: distance(source, target)
}
}).sort(dynamicSort('distance'))

// Point is invalid when equadistant, so mark with '.' instead of a value
let point = (distances[0].distance === distances[1].distance) ? '.' : distances[0].id
const point = (distances[0].distance === distances[1].distance) ? '.' : distances[0].id
return String.fromCharCode(point)
}

Expand Down Expand Up @@ -71,7 +71,7 @@ const isUnbounded = (area, grid) => {
* Creates an empty XY grid array
*/
const blankGrid = () => {
let grid = []
const grid = []
for (let x = minX; x < maxX; x++) {
grid[x] = grid[x] || []
for (let y = minY; y < maxY; y++) {
Expand Down
4 changes: 2 additions & 2 deletions 2018/day-06/coordinates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const { distance } = require('./coordinates')
describe('-- Day 6: Chronal Coordinates ---', () => {
describe('distance()', () => {
it('calculates the manhattan distance between two points', () => {
let expected = 9
let actual = distance(
const expected = 9
const actual = distance(
{ x: 1, y: 1 },
{ x: 8, y: 3 }
)
Expand Down
4 changes: 2 additions & 2 deletions 2018/day-06/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const loadInput = (callback) => {
fs.readFile(filePath, { encoding: 'utf8' }, (err, data) => {
if (err) throw err

let list = linesToArray(data).sort().map((line) => {
let coords = line.split(', ')
const list = linesToArray(data).sort().map((line) => {
const coords = line.split(', ')
return {
x: parseInt(coords[0]),
y: parseInt(coords[1])
Expand Down
Loading