Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
deddadc
started on 2017 challenges
Dec 1, 2017
2492623
spelling mistake
helloserve Dec 1, 2017
33fdff0
2017 day 2
helloserve Dec 3, 2017
6e11ddf
2017 day 3
helloserve Dec 3, 2017
26792fc
2017 day 4
helloserve Dec 4, 2017
b2e476a
map/reduce 2017 day 1
Dec 4, 2017
a10f70e
day 1 test .done() on async
Dec 4, 2017
0cbdf01
structure updates to better JS
helloserve Dec 4, 2017
4864739
map / reduce 2017 day 2
helloserve Dec 4, 2017
33b8893
2017 day 5
helloserve Dec 5, 2017
eea902a
fix split on proper regex style linefeed
Dec 5, 2017
80e830c
more reduce magic on day 2
Dec 5, 2017
f944f7e
further reduce on day 2
helloserve Dec 5, 2017
e5349a1
wrap up string split ops into functions
helloserve Dec 5, 2017
a08eb7e
day 4 reduce
helloserve Dec 5, 2017
5cc726d
2017 day 6
helloserve Dec 6, 2017
0412cac
day 6 slight refactoring to reuse part1 code
helloserve Dec 6, 2017
270526b
implement mod bankCount (thanks Phil!)
helloserve Dec 6, 2017
ef0e42c
day 6 remove extra iteration on part 2 and do array count (thanks Phil!)
helloserve Dec 6, 2017
4153500
day7 wip
helloserve Dec 7, 2017
870a757
dirty dirty day 7 part 1
helloserve Dec 7, 2017
66cb548
2017 day 7 complete
Dec 7, 2017
dc8acf9
reducer update on inputarray (day 7)
Dec 7, 2017
aa6f258
cleanup day 7
helloserve Dec 7, 2017
e119968
2017 day8
helloserve Dec 9, 2017
dc45358
2017 day 9
helloserve Dec 9, 2017
8b30a12
2017 day 10 (part 2 doesn't work)
helloserve Dec 10, 2017
5baeb21
2017 day 11 (part 2 not working)
helloserve Dec 11, 2017
c28e468
update to axial coordinates
helloserve Dec 11, 2017
c74b102
2017 day 12 wip
helloserve Dec 12, 2017
b3b2241
2017 day 12 complete
helloserve Dec 12, 2017
ce7b17a
fixup 2017 day 120
helloserve Dec 12, 2017
8a2a042
2017 day 13 part 1
helloserve Dec 13, 2017
6b47e56
2017 day 13 rekt
helloserve Dec 14, 2017
09b8ced
Bump minimist and mocha in /2017
dependabot[bot] Mar 1, 2023
5b48a57
Merge pull request #1 from helloserve/dependabot/npm_and_yarn/2017/mi…
helloserve Mar 1, 2023
e09e292
Bump braces from 3.0.2 to 3.0.3 in /2017
dependabot[bot] Jul 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions 2016/src/js/1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
L1, R3, R1, L5, L2, L5, R4, L2, R2, R2, L2, R1, L5, R3, L4, L1, L2, R3, R5, L2, R5, L1, R2, L5, R4, R2, R2, L1, L1, R1, L3, L1, R1, L3, R5, R3, R3, L4, R4, L2, L4, R1, R1, L193, R2, L1, R54, R1, L1, R71, L4, R3, R191, R3, R2, L4, R3, R2, L2, L4, L5, R4, R1, L2, L2, L3, L2, L1, R4, R1, R5, R3, L5, R3, R4, L2, R3, L1, L3, L3, L5, L1, L3, L3, L1, R3, L3, L2, R1, L3, L1, R5, R4, R3, R2, R3, L1, L2, R4, L3, R1, L1, L1, R5, R2, R4, R5, L1, L1, R1, L2, L4, R3, L1, L3, R5, R4, R3, R3, L2, R2, L1, R4, R2, L3, L4, L2, R2, R2, L4, R3, R5, L2, R2, R4, R5, L2, L3, L2, R5, L4, L2, R3, L5, R2, L1, R1, R3, R3, L5, L2, L2, R5
26 changes: 26 additions & 0 deletions 2016/src/js/Day1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function command(input) {
input = input.trim();
console.log("command " + input);

var dir = input[0];
var steps = input.substring(1, 999) * 1;
return steps;
}

function move(input) {
var commands = input.split(",");
commands.map(command);
}

function main() {
console.log("hello word");
}

function test() {
console.log(move("L1") === 1);
console.log(move("L2") === 2);
console.log(move("L1, R1") === 2);
}

test();
main();
8 changes: 8 additions & 0 deletions 2016/src/js/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "ES6"
},
"exclude": [
"node_modules"
]
}
19 changes: 19 additions & 0 deletions 2017/day1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
part1 = (input) => input.split('').reduce((accumulator, currentValue, currentIndex, array) => {
if (currentIndex < array.length - 1) {
return (currentValue === array[currentIndex + 1]) ? accumulator + parseInt(currentValue, 10) : accumulator;
}

return (currentValue === array[0] ? accumulator + parseInt(currentValue, 10) : accumulator);
}, 0);

part2 = (input) => input.split('').reduce((accumulator, currentValue, currentIndex, array) => {
var nextIndex = (array.length / 2) + currentIndex;
if (nextIndex >= array.length) {
nextIndex -= input.length;
}

return (currentValue === array[nextIndex]) ? accumulator + parseInt(currentValue, 10) : accumulator;
}, 0);


module.exports = { part1, part2 }
1 change: 1 addition & 0 deletions 2017/day1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
649713959682898259577777982349515784822684939966191359164369933435366431847754488661965363557985166219358714739318371382388296151195361571216131925158492441461844687324923315381358331571577613789649166486152237945917987977793891739865149734755993241361886336926538482271124755359572791451335842534893192693558659991171983849285489139421425933638614884415896938914992732492192458636484523228244532331587584779552788544667253577324649915274115924611758345676183443982992733966373498385685965768929241477983727921279826727976872556315428434799161759734932659829934562339385328119656823483954856427365892627728163524721467938449943358192632262354854593635831559352247443975945144163183563723562891357859367964126289445982135523535923113589316417623483631637569291941782992213889513714525342468563349385271884221685549996534333765731243895662624829924982971685443825366827923589435254514211489649482374876434549682785459698885521673258939413255158196525696236457911447599947449665542554251486847388823576937167237476556782133227279324526834946534444718161524129285919477959937684728882592779941734186144138883994322742484853925383518651687147246943421311287324867663698432546619583638976637733345251834869985746385371617743498627111441933546356934671639545342515392536574744795732243617113574641284231928489312683617154536648219244996491745718658151648246791826466973654765284263928884137863647623237345882469142933142637583644258427416972595241737254449718531724176538648369253796688931245191382956961544775856872281317743828552629843551844927913147518377362266554334386721313244223233396453291224932499277961525785755863852487141946626663835195286762947172384186667439516367219391823774338692151926472717373235612911848773387771244144969149482477519437822863422662157461968444281972353149695515494992537927492111388193837553844671719291482442337761321272333982924289323437277224565149928416255435841327756139118119744528993269157174414264387573331116323982614862952264597611885999285995516357519648695594299657387614793341626318866519144574571816535351149394735916975448425618171572917195165594323552199346814729617189679698944337146
89 changes: 89 additions & 0 deletions 2017/day10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
require('./string.js');
var file = require('./file.js');
var path = require('path');

const initialHash = () => {
var hashArray = [];
for (let i = 0; i < 256; i++) {
hashArray.push(i);
}
return hashArray;
}

const calcHash = (hash, lengths, position, skip) => {
var hashLength = hash.length;
for (let i = 0; i < lengths.length; i++) {
const length = parseInt(lengths[i]);

if (length > 1) {
if (position + length < hashLength) {
var part = hash.splice(position, length).reverse();
hash.splice(position, 0, ...part);
}
else {
var part = hash.splice(position)
.concat(hash.splice(0, position + length - hashLength))
.reverse();

var partStart = part.splice(0, hashLength - position);
var partEnd = part;
hash = [...partEnd, ...hash, ...partStart];
}
}

position += length + skip;
if (position > hashLength) {
position %= hashLength;
}
skip++;
}

return {
hash: hash,
position: position,
skip: skip
};
}

const calcDenseHash = (sparseHash) => {
var denseHash = [];
for (let j = 0; j < 16; j++) {
var denseSet = sparseHash.splice(0, 16);
denseHash = [...denseHash, xorSet(denseSet)];
}
return denseHash;
}

const xorSet = (set) =>set.slice(1).reduce((accumulator, item, index, array) =>
accumulator ^ item, set[0]);

const toBytes = (input) => input.split('').reduce((accumulator, item, index, array) =>
[...accumulator, item.charCodeAt(0)], []);

const toHex = (input) => input.reduce((accumulator, item, index, array) =>
[...accumulator, ('0' + (item & 0xFF).toString(16)).slice(-2)], []).join('');

const part1 = (input) => {
var result = calcHash(initialHash(), input.split(','), 0, 0);
return result.hash[0] * result.hash[1];
}

const part2 = (input) => {
var bytes = toBytes(input);
bytes = [...bytes, 17, 31, 73, 47, 23];
var result = {
position: 0,
skip: 0,
hash: initialHash()
}
for (let i = 0; i < 64; i++) {
result = calcHash(result.hash, bytes, result.position, result.skip);
}
var denseHash = calcDenseHash(result.hash);
return toHex(denseHash);
}

module.exports = { toBytes, xorSet, toHex, part1, part2 }

//console.log(part2('1,2,3'));
console.log(part2('14,58,0,116,179,16,1,104,2,254,167,86,255,55,122,244'));
90 changes: 90 additions & 0 deletions 2017/day11.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
require('./string.js');
var file = require('./file.js');
var path = require('path');

const followInDirection = (direction) => {
switch(direction) {
case 'n':
return { q: 0, r: -1 };
case 's':
return { q: 0, r: 1 };
case 'ne':
return { q: 1, r: -1 };
case 'se':
return { q: 1, r: 0 };
case 'nw':
return { q: -1, r: 0 };
case 'sw':
return { q: -1, r: 1 };
}
}

const stepInDirection = ({ q, r }) => {
if (q < 0 && r <= 0) {
return 'nw';
}
if (q < 0 && r > 0) {
return 'sw';
}
if (q == 0 && r < 0) {
return 'n';
}
if (q == 0 && r > 0) {
return 's';
}
if (q > 0 && r < 0) {
return 'ne';
}
if (q > 0 && r >= 0) {
return 'se';
}
}

const addDirection = (dir1, dir2) => ({ q: dir1.q + dir2.q, r: dir1.r + dir2.r });
const subDirection = (dir1, dir2) => ({ q: dir1.q - dir2.q, r: dir1.r - dir2.r });
const equalDirection = (dir1, dir2) => dir1.q == dir2.q && dir1.r == dir2.r;
const distDirection = (dir1, dir2) => (Math.abs(dir1.q - dir2.q) + Math.abs(dir1.q + dir1.r - dir2.q - dir2.r) + Math.abs(dir1.r - dir2.r)) / 2;

const findTarget = (input) => input.reduce((accumulator, step, index, array) => {
var position = addDirection(accumulator, followInDirection(step));
var further = distDirection({ q: 0, r: 0}, position) > distDirection({q: 0, r: 0}, { q:accumulator.maxQ, r: accumulator.maxR });
return {
q: position.q,
r: position.r,
maxQ : further ? position.q : accumulator.maxQ,
maxR : further ? position.r : accumulator.maxR
}
}, { q: 0, r: 0, maxQ: 0, maxR: 0 });

const stepsToTarget = (target) => {
var steps = 0;
var position = { q: 0, r: 0 };
while (!equalDirection(position, target)) {
var direction = stepInDirection(subDirection(target, position));
position = addDirection(position, followInDirection(direction));
steps++;
}
return steps;
};

const part1 = (input) => {
var target = findTarget(input.split(','));
return stepsToTarget(target);
}

const part2 = (input) => {
var target = findTarget(input.split(','));
return stepsToTarget({ q: target.maxQ, r: target.maxR });
}

module.exports = { part1, part2 }

console.log(part1('ne,ne,ne'));
console.log(part1('ne,ne,sw,sw'));
console.log(part1('ne,ne,s,s'));
console.log(part1('se,sw,se,sw,sw'));

file.load(path.resolve(__dirname, './day11.txt'), (data) => {
var result = part2(data);
console.log("day11 result", result);
});
1 change: 1 addition & 0 deletions 2017/day11.txt

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions 2017/day12.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require('./string.js');
var file = require('./file.js');
var path = require('path');

const mapNodeLinks = (item) => item.match(/\d+/g).slice(1).reduce((accumulator, link, index, array) =>
[...accumulator, parseInt(link)], []);

const buildGraph = (input) => input.reduce((accumulator, item, index, array) =>
[...accumulator, {
toTarget: false,
visited: false,
links: mapNodeLinks(item)
}], []);

const linkToTarget = (index, graph, visitList) => {
var node = graph[index];
if (node.visited) {
return;
}
node.visited = true;
for (let j = 0; j < node.links.length; j++) {
const link = node.links[j];
if (link === index) {
continue;
}
if (graph[link].toTarget) {
node.toTarget = true;
continue;
}
if (node.toTarget) {
graph[link].toTarget = true;
}
linkToTarget(link, graph);
}
}

const routeToPipe = (graph, pipe) => {
graph[pipe].toTarget = true;
linkToTarget(pipe, graph);
}

const part1 = (input) => {
var graph = buildGraph(splitOnNewLine(input));
routeToPipe(graph, 0);
return graph.reduce((accumulator, item, index, array) => accumulator + (item.toTarget ? 1 : 0), 0);
}

const part2 = (input) => {
var graph = buildGraph(splitOnNewLine(input));
var count = 0;
var pipe = 0;
while (pipe !== -1) {
count++;
routeToPipe(graph, pipe);
pipe = graph.findIndex((node) => !node.toTarget);
}
return count;
}

module.exports = { part1, part2 }

//console.log(part2('0 <-> 2\r\n1 <-> 1\r\n2 <-> 0, 3, 4\r\n3 <-> 2, 4\r\n4 <-> 2, 3, 6\r\n5 <-> 6\r\n6 <-> 4, 5'));

// file.load(path.resolve(__dirname, './day12.txt'), (data) => {
// var result = part2(data);
// console.log(result);
// });
Loading