Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const solvePart1 = (input) => {
- const data = parse(input);
- let sum = 0;
- for (const part of data.parts) {
- let next = "in";
- while (next != "A" && next != "R") {
- for (const flow of data.workflows[next]) {
- if (!flow.condition) {
- next = flow.next;
- break;
- }
- if (flow.condition == "<" && part[flow.category] < flow.value) {
- next = flow.next;
- break;
- } else if (flow.condition == ">" && part[flow.category] > flow.value) {
- next = flow.next;
- break;
- }
- }
- }
- if (next == "A") {
- sum += part.x + part.m + part.a + part.s;
- }
- }
- return sum;
- };
Advertisement
Add Comment
Please, Sign In to add comment