This file contains hidden or 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
function adventOfCode2017_Day01_Part1(str) { | |
str += str[0] | |
let sum = 0 | |
for (let i = 0; i < str.length - 1; i++) { | |
if (str[i] == str[i + 1]) { | |
sum += Number(str[i]) | |
} | |
} | |
return sum | |
} |
This file contains hidden or 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
function adventOfCode2015_Day01_Part1(str) { | |
return Array.prototype.reduce.call(str, (floor, char) => (floor + (char === '(' ? 1 : -1)), 0) | |
} | |
function adventOfCode2015_Day01_Part2(str) { | |
let floor = 0 | |
let position = 1 | |
for (const char of str) { | |
floor += char === '(' ? 1 : -1 | |
if (floor === -1) { |
This file contains hidden or 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
function vectorMove(vector) { | |
for (let i = vector.length - 2; i >= 0; i--) { | |
if (vector[i] === 0) continue | |
for (let j = i + 1; j < vector.length; j++) { | |
if (vector[i] !== vector[j] && vector[j] !== 0) break | |
if (vector[j] === 0) { | |
vector[j] = vector[i] | |
} else { | |
vector[j] *= 2 | |
} |
This file contains hidden or 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
class MagicString { | |
static #convertStringToData(str) { | |
return {str, start: 0, length: str.length} | |
} | |
static #makeDataCopy(data) { | |
return data.map((data) => ({...data})) | |
} | |
static #splitData(index, data) { | |
let offset = index | |
const offsetIndex = data.findIndex(({length}) => { |
This file contains hidden or 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
function getElfCalories(str) { | |
return str.trim().split('\n').reduce((arr, val) => { | |
if (val === '') { | |
arr.push(0) | |
} else { | |
const maxIndex = arr.length - 1 | |
arr[maxIndex] = arr[maxIndex] + Number(val) | |
} | |
return arr | |
}, [0]) |
This file contains hidden or 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
function adventOfCode2023_Day01_Part1(str) { | |
return str.trim().split('\n').map((line) => { | |
const firstNum = /\d/.exec(line)[0] | |
const lastNum = /(\d)[a-zA-Z]*?$/.exec(line)[1] | |
return Number(firstNum + lastNum) | |
}).reduce((total, num) => total + num, 0) | |
} | |
function adventOfCode2023_Day01_Part2(str) { | |
const CONVERSION = new Map([ |
This file contains hidden or 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
default persistent.brightness = 1.0 | |
screen preferences(): | |
# Add these somewhere inside | |
label _("Brightness") | |
bar value VariableValue("persistent.brightness", 1.0) |
This file contains hidden or 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
function adventOfCode2024_Day01_Part1(str) { | |
const numsLeft = [] | |
const numsRight = [] | |
str.trim().split('\n').forEach((line) => { | |
const [numLeft,numRight] = line.split(/\s+/) | |
numsLeft.push(Number(numLeft)) | |
numsRight.push(Number(numRight)) | |
}) | |
const numSort = (a,b) => a < b ? -1 : 1 | |
numsLeft.sort(numSort) |