Skip to content

Instantly share code, notes, and snippets.

View devNoiseConsulting's full-sized avatar

Michael Flynn devNoiseConsulting

View GitHub Profile
@devNoiseConsulting
devNoiseConsulting / ac20171208.js
Created January 3, 2018 03:22
I Heard You Like Registers - Advent of Code - 20171208
let checkCondtion = function(condition, registers) {
let test = false;
switch (condition[2]) {
case '>':
if (registers[condition[1]] > condition[3]) {
test = true;
}
break;
case '<':
if (registers[condition[1]] < condition[3]) {
@devNoiseConsulting
devNoiseConsulting / ac20171207.js
Last active January 3, 2018 03:20
Recursive Circus - Advent of Code - 20171207
let test = `llyhqfe (21)
vpbdpfm (74) -> ndegtj, wnwxs
dosteiu (262) -> vliyv, rfxmk, nulxd, tckql
leqnli (222) -> wuttw, nckca
cgztcyz (59) -> zbtmpkc, lleaucw, zxvjkqv, tqjyoj
dqfti (67)
vsjhe (34) -> zpbbgqh, menyi, ksasli, uahdbi, ccfiz, kdwmlx
ntzuhe (98)
mpjrzt (53)
dnzll (23)
@devNoiseConsulting
devNoiseConsulting / ac20171206.js
Created January 3, 2018 03:20
Memory Reallocation - Advent of Code - 20171206
let memoryReallocation = function(memory) {
let previousStates = [memory.join(',')];
let stateSeen = false;
let loopStart = -1;
console.log(previousStates.length, memory.length, memory.join(','));
while (!stateSeen) {
let blocks = Math.max(...memory);
let index = memory.indexOf(blocks);
memory[index++] = 0;
@devNoiseConsulting
devNoiseConsulting / ac20171205.js
Created January 3, 2018 03:19
A Maze of Twisty Trampolines, All Alike - Advent of Code - 20171205
let twistyTrampolines = function(jumps) {
let steps = 0;
let inside = true;
let index = 0;
while (inside) {
if ( isNaN(index)) {
inside = false;
}
let oldJump = jumps[index];
let oldIndex = index;
@devNoiseConsulting
devNoiseConsulting / ac20171204.js
Created January 3, 2018 03:18
High-Entropy Passphrases - Advent of Code - 20171204
let test = `nyot babgr babgr kqtu kqtu kzshonp ylyk psqk
iix ewj rojvbkk phrij iix zuajnk tadv givslju ewj bda
isjur jppvano vctnpjp ngwzdq pxqfrk mnxxes zqwgnd giqh
ojufqke gpd olzirc jfao cjfh rcivvw pqqpudp
ilgomox extiffg ylbd nqxhk lsi isl nrho yom
feauv scstmie qgbod enpltx jrhlxet qps lejrtxh
wlrxtdo tlwdxor ezg ztp uze xtmw neuga aojrixu zpt
wchrl pzibt nvcae wceb
rdwytj kxuyet bqnzlv nyntjan dyrpsn zhi kbxlj ivo
dab mwiz bapjpz jbzppa
@devNoiseConsulting
devNoiseConsulting / ac20171203.js
Created January 3, 2018 03:14
Spiral Memory - Advent of Code - 20171203
let findMoves = function(location) {
let previousSquare = Math.floor(Math.sqrt(location));
previousSquare = previousSquare % 2 == 0 ? previousSquare - 1 : previousSquare;
let sideSize = previousSquare + 1;
previousSquare *= previousSquare;
console.log('debug', previousSquare, Math.floor(sideSize / 2), Math.floor((location - previousSquare) % (sideSize / 2)));
return Math.floor(sideSize / 2) + Math.floor((location - previousSquare) % (sideSize / 2));
};
@devNoiseConsulting
devNoiseConsulting / ac20171202.js
Created January 3, 2018 03:13
Corruption Checksum - Advent of Code - 20171202
let spreadsheet = `179 2358 5197 867 163 4418 3135 5049 187 166 4682 5080 5541 172 4294 1397
2637 136 3222 591 2593 1982 4506 195 4396 3741 2373 157 4533 3864 4159 142
1049 1163 1128 193 1008 142 169 168 165 310 1054 104 1100 761 406 173
200 53 222 227 218 51 188 45 98 194 189 42 50 105 46 176
299 2521 216 2080 2068 2681 2376 220 1339 244 605 1598 2161 822 387 268
1043 1409 637 1560 970 69 832 87 78 1391 1558 75 1643 655 1398 1193
90 649 858 2496 1555 2618 2302 119 2675 131 1816 2356 2480 603 65 128
2461 5099 168 4468 5371 2076 223 1178 194 5639 890 5575 1258 5591 6125 226
204 205 2797 2452 2568 2777 1542 1586 241 836 3202 2495 197 2960 240 2880
560 96 336 627 546 241 191 94 368 528 298 78 76 123 240 563
@devNoiseConsulting
devNoiseConsulting / ac20171201.js
Created January 3, 2018 03:12
Inverse Captcha - Advent of Code - 20171201
let circularMatchSum = function(numbers) {
numbers = numbers
.toString()
.split('')
.map(v => parseInt(v));
let [lastDigit] = numbers.slice(-1);
return numbers.reduce((acc, v, i) => {
if (v == lastDigit) {
acc += v;
@devNoiseConsulting
devNoiseConsulting / gistScraper.js
Last active January 3, 2018 19:00
A javascript snippet to extract the description and link of each gist on the page.
// Starting point was based off of an answer on StackOverflow
// https://stackoverflow.com/a/3824292/187675
let grabMyGists = function(userName, linkMatch, descMatch) {
let links = [...document.links].filter(
link =>
link.hostname === location.hostname &&
link.href.includes(userName) &&
link.text.match(linkMatch)
);
@devNoiseConsulting
devNoiseConsulting / dp20171129.js
Created November 29, 2017 14:28
More Reliably Terrible Sort - PhillyDev Slack #daily_programmer - 20171129
let permutations = function(string) {
if (Array.isArray(string)) {
string = string.join(',');
}
if (string.length == 1) {
return [string];
} else {
return string.split(',').reduce((acc, l, i, arr) => {
return acc.concat(
permutations(