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 puzzleInput = `` | |
// Part 1 | |
const parseInput = (input) => { | |
return input.split('\n') | |
} | |
const parseRecord = (record) => { | |
const regex = /(\d+)\-(\d+) ([a-z]): ([a-z]*)/gi | |
return [...record.matchAll(regex)][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
// Part 1 | |
const input = `` | |
const findPairsForSum = (numbers, sum) => { | |
return numbers.reduce((acc, num1) => { | |
if (acc) { return acc } | |
const inner = numbers.find((num2) => num1 + num2 === sum) | |
if (inner) { return [num1, inner] } | |
}, null) | |
} |
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
// Part 1 | |
const parseCommand = (opcode) => { | |
const str = `${opcode}` | |
let modes = [] | |
if (str.length > 2) { | |
opcode = +str.substr(-2) | |
modes = str.substr(0, str.length - 2).split('').reverse().map(x => +x) | |
} | |
return { opcode, modes } | |
} |
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
// Part 1 | |
const parseCommand = (opcode) => { | |
const str = `${opcode}` | |
let modes = [] | |
if (str.length > 2) { | |
opcode = +str.substr(-2) | |
modes = str.substr(0, str.length - 2).split('').reverse().map(x => +x) | |
} | |
return { opcode, modes } | |
} |
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
// Part 1 | |
const searchForSatellite = (area, name, payload) => { | |
let foundChild = false | |
if (typeof area[name] === 'boolean') { | |
area[name] = payload | |
foundChild = true | |
return foundChild | |
} | |
Object.keys(area).filter(x => typeof area[x] === 'object').forEach(key => { | |
foundChild = searchForSatellite(area[key], name, payload) || foundChild |
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
// Part 1 | |
const isNumberGood = (num) => { | |
const digits = num.toString().split('').map(x => +x) | |
return digits.every((digit, index, arr) => digit >= (arr[index - 1] || 0)) && | |
digits.some((digit, index, arr) => digit === arr[index - 1]) | |
} | |
const countPasswordOptions = (input) => { | |
const range = input.split('-').map(x => +x) | |
let count = 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
// Part 1 | |
const parsePoint = (move) => { | |
const num = parseInt(move.match(/\d+/gi), 10) | |
switch(move[0]) { | |
case 'R': return { num, axis: 'x' } | |
case 'L': return { num: num * -1, axis: 'x' } | |
case 'D': return { num, axis: 'y' } | |
case 'U': return { num: num * -1, axis: 'y' } | |
} | |
} |
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
// Part 1 | |
const handleInstruction = ([command, src1, src2, dest], integers) => { | |
switch(command) { | |
case 1: | |
integers[dest] = integers[src1] + integers[src2] | |
break | |
case 2: | |
integers[dest] = integers[src1] * integers[src2] | |
break | |
case 99: return true |
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
// Part 1 | |
const fillEmUp = (modules) => { | |
return modules.reduce((acc, mass) => { | |
return acc + (Math.floor(mass / 3) - 2) | |
}, 0) | |
} | |
// Part 2 | |
const fuelForMass = (mass) => { | |
const fuel = (Math.floor(mass / 3) - 2) |
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
<ion-header> | |
<ion-toolbar> | |
<ion-title>About</ion-title> | |
</ion-toolbar> | |
</ion-header> | |
<ion-content> | |
<ion-list> | |
<ion-item> | |
<ion-label position="floating">This is a label for a text field</ion-label> |