Skip to content

Instantly share code, notes, and snippets.

View pengx17's full-sized avatar
🛫

Peng Xiao pengx17

🛫
View GitHub Profile
function toDec(num) {
return parseInt(num, 2);
}
/**
*
* @param {string} input
* @returns {[number, number]}
*/
function read(input, start, length) {
const input = `
1163751742
1381373672
2136511328
3694931569
7463417111
1319128137
1359912421
3125421639
1293138521
const input = `NNCB
CH -> B
HH -> N
CB -> H
NH -> C
HB -> C
HC -> B
HN -> C
NN -> C
const input = `6,10
0,14
9,10
0,3
10,4
4,11
6,0
6,12
4,1
0,13
let input = `fs-end
he-DX
fs-he
start-DX
pj-DX
end-zg
zg-sl
zg-pj
pj-he
RW-he
let input = `5483143223
2745854711
5264556173
6141336146
6357385478
4167524645
2176841721
6882881134
4846848554
5283751526`;
let raw = `[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
(((({<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[[]
[<(<(<(<{}))><([]([]()
<{([([[(<>()){}]>(<<{{
<{([{{}}[<[[[<>{}]]]>[]]`;
const input = `2199943210
3987894921
9856789892
8767896789
9899965678`;
function run(input = "") {
const lines = input.split("\n");
const matrix = lines.map((line) => line.split(""));
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);
@pengx17
pengx17 / 6.js
Last active December 9, 2021 14:36
advent code 2021
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;