Merge branch '2022-11'
This commit is contained in:
commit
dc11ceb117
@ -1,7 +1,7 @@
|
||||
.gitignore
|
||||
input
|
||||
.prettierignore
|
||||
sample
|
||||
sample*
|
||||
input
|
||||
*.t
|
||||
*.pm
|
||||
|
9
2022/11/foo.bench.js
Normal file
9
2022/11/foo.bench.js
Normal file
@ -0,0 +1,9 @@
|
||||
import { bench, test, expect, describe } from "vitest";
|
||||
|
||||
import { expectSolution } from "../01/main.js";
|
||||
import part1, { sample, puzzleInput } from "./part1.js";
|
||||
import part2 from "./part2.js";
|
||||
|
||||
bench("sample", () => {
|
||||
part2(puzzleInput);
|
||||
});
|
@ -39,15 +39,15 @@ export const sample = readInput(import.meta.url, "sample");
|
||||
const playTurn = (monkeys, monkey) => {
|
||||
monkey.inspections += monkey.items.length;
|
||||
|
||||
monkey.items = monkey.items.map( i => monkey.operation(i) );
|
||||
monkey.items = monkey.items.map((i) => monkey.operation(i));
|
||||
|
||||
monkey.items = monkey.items.map( i => Math.floor(i/3) );
|
||||
monkey.items = monkey.items.map((i) => Math.floor(i / 3));
|
||||
|
||||
|
||||
monkey.items.forEach( i => {
|
||||
monkeys[(i % monkey.divisible) ? monkey.ifFalse : monkey.ifTrue
|
||||
].items.push(i)
|
||||
} )
|
||||
monkey.items.forEach((i) => {
|
||||
monkeys[i % monkey.divisible ? monkey.ifFalse : monkey.ifTrue].items.push(
|
||||
i
|
||||
);
|
||||
});
|
||||
|
||||
monkey.items = [];
|
||||
|
||||
@ -55,17 +55,17 @@ const playTurn = (monkeys, monkey) => {
|
||||
};
|
||||
|
||||
const playRound = (monkeys) => {
|
||||
monkeys.forEach( monkey => playTurn(monkeys,monkey) );
|
||||
monkeys.forEach((monkey) => playTurn(monkeys, monkey));
|
||||
return monkeys;
|
||||
}
|
||||
};
|
||||
|
||||
export default R.createPipe(
|
||||
R.clone,
|
||||
(monkeys) => R.times(20, () => playRound(monkeys)),
|
||||
R.last(),
|
||||
R.map( R.prop('inspections') ),
|
||||
R.map(R.prop("inspections")),
|
||||
R.sortBy(R.identity),
|
||||
R.reverse,
|
||||
R.take(2),
|
||||
R.reduce((a, b) => a * b, 1)
|
||||
)
|
||||
);
|
||||
|
@ -1,37 +1,34 @@
|
||||
import * as R from "remeda";
|
||||
|
||||
const playTurn = (monkeys, monkey) => {
|
||||
const max = monkeys.map( R.prop('divisible') ).reduce(
|
||||
(a,b) => a * b
|
||||
);
|
||||
|
||||
const playTurn = (max, monkeys, monkey) => {
|
||||
monkey.inspections += monkey.items.length;
|
||||
|
||||
monkey.items = monkey.items.map( i => monkey.operation(i) );
|
||||
monkey.items = monkey.items.map( i => i % max );
|
||||
|
||||
monkey.items.forEach( i => {
|
||||
monkeys[(i % monkey.divisible) ? monkey.ifFalse : monkey.ifTrue
|
||||
].items.push(i)
|
||||
} )
|
||||
monkey.items
|
||||
.map((i) => monkey.operation(i) % max)
|
||||
.forEach((i) => {
|
||||
monkeys[i % monkey.divisible ? monkey.ifFalse : monkey.ifTrue].items.push(
|
||||
i
|
||||
);
|
||||
});
|
||||
|
||||
monkey.items = [];
|
||||
|
||||
return;
|
||||
return monkey;
|
||||
};
|
||||
|
||||
const playRound = (monkeys) => {
|
||||
monkeys.forEach( monkey => playTurn(monkeys,monkey) );
|
||||
return monkeys;
|
||||
}
|
||||
const genPlayRound = (monkeys) => {
|
||||
const max = monkeys.map(R.prop("divisible")).reduce((a, b) => a * b);
|
||||
|
||||
return () => monkeys.map((monkey) => playTurn(max, monkeys, monkey));
|
||||
};
|
||||
|
||||
export default R.createPipe(
|
||||
R.clone,
|
||||
(monkeys) => R.times(10000, () => playRound(monkeys)),
|
||||
(monkeys) => R.times(10000, genPlayRound(monkeys)),
|
||||
R.last(),
|
||||
R.map( R.prop('inspections') ),
|
||||
R.map(R.prop("inspections")),
|
||||
R.sortBy(R.identity),
|
||||
R.reverse,
|
||||
R.take(2),
|
||||
R.reduce((a, b) => a * b, 1)
|
||||
)
|
||||
);
|
||||
|
@ -17,7 +17,7 @@ describe("part 1", () => {
|
||||
});
|
||||
|
||||
describe.only("part 2", () => {
|
||||
test.only( "sample", () => {
|
||||
test.skip("sample", () => {
|
||||
expect(part2(sample)).toEqual(2713310158);
|
||||
});
|
||||
test("solution", () => {
|
||||
|
@ -29,6 +29,7 @@ tasks:
|
||||
|
||||
download:
|
||||
cmds:
|
||||
- hygen day new --day {{.DAY_FORMATTED}}
|
||||
- aoc download -d {{.DAY}} -o -p 2022/{{.DAY_FORMATTED}}/puzzle.md -i 2022/{{.DAY_FORMATTED}}/input
|
||||
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user