Skip to content

apeltz/AdventOfCode2017

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AdventOfCode2017

Solutions

Table of Contents

Day 1 Pt. 1 - Solution 1 (Javascript)

Challenge

[AoC 2017 Day 1](http://adventofcode.com/2017/day/1) - Take a sequence of digits and finds the sum of all digits that match the next digit in the list.

Included Functions

reverseCapchaLoop

Takes a sequence of digits and finds the sum of all digits that match the next digit in the list. Note: assume the sequence wraps, where the next digit for the last digit in the sequence would be the first digit of the sequence.

Parameters

  • digitString String A string of digits

Examples

reverseCapchaLoop('123425');
// => 4
reverseCapchaLoop('91212129');
// => 9

Returns Number Sum of all digits that match the next digit in the sequence

Day 1 Pt. 2 - Solution 1 (Javascript)

Challenge

[AoC 2017 Day 1](http://adventofcode.com/2017/day/1) - Take a sequence of digits and finds the sum of all digits that match the digit halfway around in the list.

Included Functions

reverseCapchaLoopHalfWay

Takes a sequence of digits and finds the sum of all digits that match the next digit in the list. Note: assume the sequence wraps, where the next digit for the last digit in the sequence would be the first digit of the sequence.

Parameters

  • digitString String A string of digits

Examples

reverseCapchaLoopHalfWay('12131415');
// => 5

Returns Number Sum of all digits that match the next digit in the sequence

Day 2 Pt. 1 - Solution 1 (Javascript)

Challenge

[AoC 2017 Day 2](http://adventofcode.com/2017/day/2) - Determine the difference between the largest value and the smallest value; the checksum is the sum of all of these differences.

Included Functions

checkSumReducer

Calculates the sum of the difference between the highest and lowest integer in provided row(s) of integers

Parameters

  • digitString String Integers separated by tabs and newline characters, where each newline denotes the end of a row

Examples

const digits = `5 1 9 5
                7 5 3
                2 4 6 8`;
checkSumReducer(digitString);
// => 18

Returns Number The sum of the differences of all rows

getDiffReducer

Itererates through an array of integers to find the max, min, and difference between max and min, based on all integers in the array

Parameters

  • arr Array Array of integers

Examples

getDiff([ 3, 5, 9, 1, 12, 2]);
// => { min: 1, max: 12, diff: 11 }

Returns Object Object containing the current max, min, and max-min for the row

Day 2 Pt. 2 - Solution 1 (Javascript)

Challenge

[AoC 2017 Day 2](http://adventofcode.com/2017/day/2) - Determine the difference between the only two evenly divisible integers in the sequence; the checksum is the sum of all of these differences.

Included Functions

checkSumDivisible

Calculates the sum of the quotients of the highest and lowest evenly-divisible integers in provided row(s) of integers

Parameters

  • digitString String Integers separated by tabs and newline characters, where each newline denotes the end of a row

Examples

const digits = `5 9 2 8
                9 4 7 3
                3 8 6 5`;
checkSumDivisible(digitString);
// => 9

Returns Number The sum of the quotient of all rows

getDiffDivisible

Itererates through an array of integers to find two evenly divisible integers, returning the quotient of those integers, else 0

Parameters

  • arr Array Array of integers

Examples

getDiff([ 3, 5, 12, 7]);
// => 4

Returns Number Quotient of divisible integers

Day 3 Pt. 1 - Solution 1 (Javascript)

Challenge

[AoC 2017 Day 3](http://adventofcode.com/2017/day/3) - Determine the length of the shortest path between the location of a data node in a grid.

Included Functions

spiralNumberDistanceLoop

Calculates the shortest path from the number to the center of a two-dimensional grid

Parameters

  • n Number Number for which to calculate the distance from the center

Examples

spiralNumberDistanceLoop(361567);
// => 326

Returns Number Manhattan Distance from center of the grid

Day 3 Pt. 1 - Solution 2 (Javascript)

Challenge

[AoC 2017 Day 3](http://adventofcode.com/2017/day/3) - Determine the length of the shortest path between the location of a data node in a grid.

Included Functions

spiralNumberDistance

Calculates the shortest path from the number to the center of a two-dimensional grid

Parameters

  • n Number Number for which to calculate the distance from the center

Examples

spiralNumberDistance(361567);
// => 326

Returns Number Manhattan Distance from center of the grid

Day 3 Pt. 2 - Solution 1 (Javascript)

Challenge

[AoC 2017 Day 3](http://adventofcode.com/2017/day/3) - Determine the length of the shortest path between the location of a data node in a grid.

Included Functions

Releases

No releases published

Packages