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
function toDec(num) { | |
return parseInt(num, 2); | |
} | |
/** | |
* | |
* @param {string} input | |
* @returns {[number, number]} | |
*/ | |
function read(input, start, length) { |
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 input = ` | |
1163751742 | |
1381373672 | |
2136511328 | |
3694931569 | |
7463417111 | |
1319128137 | |
1359912421 | |
3125421639 | |
1293138521 |
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 input = `NNCB | |
CH -> B | |
HH -> N | |
CB -> H | |
NH -> C | |
HB -> C | |
HC -> B | |
HN -> C | |
NN -> C |
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 input = `6,10 | |
0,14 | |
9,10 | |
0,3 | |
10,4 | |
4,11 | |
6,0 | |
6,12 | |
4,1 | |
0,13 |
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
let input = `fs-end | |
he-DX | |
fs-he | |
start-DX | |
pj-DX | |
end-zg | |
zg-sl | |
zg-pj | |
pj-he | |
RW-he |
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
let input = `5483143223 | |
2745854711 | |
5264556173 | |
6141336146 | |
6357385478 | |
4167524645 | |
2176841721 | |
6882881134 | |
4846848554 | |
5283751526`; |
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
let raw = `[({(<(())[]>[[{[]{<()<>> | |
[(()[<>])]({[<{<<[]>>( | |
{([(<{}[<>[]}>{[]{[(<()> | |
(((({<>}<{<{<>}{[]{[]{} | |
[[<[([]))<([[{}[[()]]] | |
[{[{({}]{}}([{[{{{}}([] | |
{<[[]]>}<{[{[{[]{()[[[] | |
[<(<(<(<{}))><([]([]() | |
<{([([[(<>()){}]>(<<{{ | |
<{([{{}}[<[[[<>{}]]]>[]]`; |
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 input = `2199943210 | |
3987894921 | |
9856789892 | |
8767896789 | |
9899965678`; | |
function run(input = "") { | |
const lines = input.split("\n"); | |
const matrix = lines.map((line) => line.split("")); |
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
function permutate(arr = []) { | |
let res = []; | |
if (arr.length === 1) { | |
return [arr]; | |
} | |
for (let i = 0; i < arr.length; i++) { | |
let c = arr[i]; | |
let rest = arr.slice(); | |
rest.splice(i, 1); |
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 input = `1,1,1,1,3,1,4,1,4,1,1,2,5,2,5,1,1,1,4,3,1,4,1,1,1,1,1,1,1,2,1,2,4,1,1,1,1,1,1,1,3,1,1,5,1,1,2,1,5,1,1,1,1,1,1,1,1,4,3,1,1,1,2,1,1,5,2,1,1,1,1,4,5,1,1,2,4,1,1,1,5,1,1,1,1,5,1,3,1,1,4,2,1,5,1,2,1,1,1,1,1,3,3,1,5,1,1,1,1,3,1,1,1,4,1,1,1,4,1,4,3,1,1,1,4,1,2,1,1,1,2,1,1,1,1,5,1,1,3,5,1,1,5,2,1,1,1,1,1,4,4,1,1,2,1,1,1,4,1,1,1,1,5,3,1,1,1,5,1,1,1,4,1,4,1,1,1,5,1,1,3,2,2,1,1,1,4,1,3,1,1,1,2,1,3,1,1,1,1,4,1,1,1,1,2,1,4,1,1,1,1,1,4,1,1,2,4,2,1,2,3,1,3,1,1,2,1,1,1,3,1,1,3,1,1,4,1,3,1,1,2,1,1,1,4,1,1,3,1,1,5,1,1,3,1,1,1,1,5,1,1,1,1,1,2,3,4,1,1,1,1,1,2,1,1,1,1,1,1,1,3,2,2,1,3,5,1,1,4,4,1,3,4,1,2,4,1,1,3,1`; | |
const cache = {}; | |
// a fish starts with 6 (8 - 2) | |
function countFish(remainingTime) { | |
if (cache[remainingTime]) { | |
return cache[remainingTime]; | |
} | |
let originalRemainingTime = remainingTime; |