Skip to content

Commit

Permalink
Merge pull request #12 from dieseltravis/glitch
Browse files Browse the repository at this point in the history
Glitch day 4
  • Loading branch information
dieseltravis authored Dec 4, 2023
2 parents c559f8b + 0373de4 commit b5cc91c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ my 2023 solutions on glitch: [branch-three-oviraptor](https://branch-three-ovira

also on github: [dieseltravis/aoc2023](https://github.com/dieseltravis/aoc2023)

[![Days completed in a row](https://img.shields.io/badge/⭐%20days%20in%20a%20row-3-blueviolet)](https://adventofcode.com/2023/) [![glitch](https://shields.io/badge/glitch-%F0%9F%91%8D%F0%9F%8E%8F-blue?logo=glitch&logoColor=violet)](https://glitch.com/)
[![Days completed in a row](https://img.shields.io/badge/⭐%20days%20in%20a%20row-4-blueviolet)](https://adventofcode.com/2023/) [![glitch](https://shields.io/badge/glitch-%F0%9F%91%8D%F0%9F%8E%8F-blue?logo=glitch&logoColor=violet)](https://glitch.com/)

[![Node.js CI](https://github.com/dieseltravis/aoc2023/actions/workflows/node.js.yml/badge.svg)](https://github.com/dieseltravis/aoc2023/actions/workflows/node.js.yml) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fdieseltravis%2Faoc2023.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fdieseltravis%2Faoc2023?ref=badge_shield) [![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?logo=javascript)](https://github.com/standard/semistandard)

## solutions:
1. [day one](https://branch-three-oviraptor.glitch.me/day/01)
2. [day two](https://branch-three-oviraptor.glitch.me/day/02)
3. [day three](https://branch-three-oviraptor.glitch.me/day/03)
<!--
4. [day four](https://branch-three-oviraptor.glitch.me/day/04)
<!--
5. [day five](https://branch-three-oviraptor.glitch.me/day/05)
6. [day six](https://branch-three-oviraptor.glitch.me/day/06)
7. [day seven](https://branch-three-oviraptor.glitch.me/day/07)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "branch-three-oviraptor",
"version": "2023.12.03",
"version": "2023.12.04",
"description": "Travis's Advent of Code 2023",
"author": "Travis Hardiman",
"homepage": "https://branch-three-oviraptor.glitch.me/",
Expand Down
37 changes: 35 additions & 2 deletions public/funs.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,43 @@
},
day4: {
part1: (data) => {
return data;
const lotto = data.trim().split('\n').map(cals => {
const line = cals.split('|');
const card = line[0].split(':');
const values = card[1].trim().split(/\s+/).map(Number);
const winner = line[1].trim().split(/\s+/).map(Number);
const good = values.filter(n => winner.includes(n));
let score = good.length;
if (score > 0) {
score = 2 ** (score - 1);
}
return score;
});
return lotto.reduce((acc, item) => acc + item, 0);
},
part2: (data) => {
return data;
const copies = {};
const lotto = data.trim().split('\n').map(cals => {
const line = cals.split('|');
const card = line[0].split(':');
const num = +card[0].match(/\d+/)[0];
const values = card[1].trim().split(/\s+/).map(Number);
const winner = line[1].trim().split(/\s+/).map(Number);
const good = values.filter(n => winner.includes(n));
const score = good.length;
if (score > 0) {
const inc = 1 + (copies[num] || 0);
for (let i = num + 1; i <= num + score; i++) {
if (!copies[i]) {
copies[i] = 0;
}
copies[i] += inc;
}
}
return score;
});
console.log(lotto, copies);
return lotto.length + Object.values(copies).reduce((acc, item) => acc + item, 0);
}
},
day5: {
Expand Down
2 changes: 1 addition & 1 deletion views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ <h2>solutions:</h2>
<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>
<li><a href="/day/07">day 07</a></li>
Expand Down

0 comments on commit b5cc91c

Please sign in to comment.