Skip to content

Commit

Permalink
Merge pull request #3 from dieseltravis/day03
Browse files Browse the repository at this point in the history
Day 03
  • Loading branch information
dieseltravis authored Dec 4, 2024
2 parents ebee172 + 2d32291 commit b9e586b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions public/funs.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,30 @@
}
},
day3: {
part1: d => d,
part2: d => d
part1: (data) => {
const rxmul = /mul\((-?\d+),(-?\d+)\)/g;
const input = [...data.trim().matchAll(rxmul)];
console.log(input);
const sum = input.reduce((acc, r) => acc + r[1] * r[2], 0);
return sum;
},
part2: (data) => {
const rxmul = /mul\((-?\d+),(-?\d+)\)|(do)\(\)|(don't)\(\)/g;
const input = [...data.trim().matchAll(rxmul)];
console.log(input);
let yes = true;
const sum = input.reduce((acc, r) => {
if (r[3] === 'do') {
yes = true;
} else if (r[4] === 'don\'t') {
yes = false;
} else if (yes) {
acc += r[1] * r[2];
}
return acc;
}, 0);
return sum;
}
},
day4: {
part1: d => d,
Expand Down
2 changes: 1 addition & 1 deletion views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ <h2>solutions:</h2>
<ol>
<li><a href="/day/01">day 01</a></li>
<li><a href="/day/02">day 02</a></li>
<!--
<li><a href="/day/03">day 03</a></li>
<!--
<li><a href="/day/04">day 04</a></li>
<li><a href="/day/05">day 05</a></li>
<li><a href="/day/06">day 06</a></li>
Expand Down

0 comments on commit b9e586b

Please sign in to comment.