Skip to content

Commit

Permalink
day 2
Browse files Browse the repository at this point in the history
  • Loading branch information
shahata committed Dec 2, 2023
1 parent 9c8011c commit 152578d
Show file tree
Hide file tree
Showing 5 changed files with 355 additions and 137 deletions.
78 changes: 78 additions & 0 deletions src/2023/day02.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8" />
<title>Day 2 - Advent of Code 2023</title>
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet'
type='text/css'>
<link rel="stylesheet" type="text/css" href="../static/style.css" />
<link rel="stylesheet alternate" type="text/css" href="../static/highcontrast.css" title="High Contrast" />
<link rel="shortcut icon" href="../static/favicon.png" />
</head>
<body>
<header>
<div>
<h1 class="title-global"><a href="index.html">Advent of Code</a></h1>
<nav>
<ul>
<li><a href="events.html">[Events]</a></li>
<li><a href="leaderboard.html">[Leaderboard]</a></li>
<li><a href="solver.html">[Solver]</a></li>
</ul>
</nav>
<div class="user">Shahar Talmi <a class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <a
href="https://www.wix.engineering/" target="_blank" class="sponsor-badge"
title="Member of sponsor: Wix Engineering">(Sponsor)</a> <span class="star-count">50*</span></div>
</div>
<div>
<h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=</span><a
href="index.html">2023</a><span class="title-event-wrap">;</span></h1>
</div>
</header>
<main>
<article class="day-desc"><h2>--- Day 2: Cube Conundrum ---</h2><p>You're launched high into the atmosphere! The apex of your trajectory just barely reaches the surface of a large island floating in the sky. You gently land in a fluffy pile of leaves. It's quite cold, but you don't see much snow. An Elf runs over to greet you.</p>
<p>The Elf explains that you've arrived at <em>Snow Island</em> and apologizes for the lack of snow. He'll be happy to explain the situation, but it's a bit of a walk, so you have some time. They don't get many visitors up here; <span title="No, the Elf's name is not 'WOPR'. It's Joshua.">would you like to play a game</span> in the meantime?</p>
<p>As you walk, the Elf shows you a small bag and some cubes which are either red, green, or blue. Each time you play this game, he will hide a secret number of cubes of each color in the bag, and your goal is to figure out information about the number of cubes.</p>
<p>To get information, once a bag has been loaded with cubes, the Elf will reach into the bag, grab a handful of random cubes, show them to you, and then put them back in the bag. He'll do this a few times per game.</p>
<p>You play several games and record the information from each game (your puzzle input). Each game is listed with its ID number (like the <code>11</code> in <code>Game 11: ...</code>) followed by a semicolon-separated list of subsets of cubes that were revealed from the bag (like <code>3 red, 5 green, 4 blue</code>).</p>
<p>For example, the record of a few games might look like this:</p>
<pre><code>Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
</code></pre>
<p>In game 1, three sets of cubes are revealed from the bag (and then put back again). The first set is 3 blue cubes and 4 red cubes; the second set is 1 red cube, 2 green cubes, and 6 blue cubes; the third set is only 2 green cubes.</p>
<p>The Elf would first like to know which games would have been possible if the bag contained <em>only 12 red cubes, 13 green cubes, and 14 blue cubes</em>?</p>
<p>In the example above, games 1, 2, and 5 would have been <em>possible</em> if the bag had been loaded with that configuration. However, game 3 would have been <em>impossible</em> because at one point the Elf showed you 20 red cubes at once; similarly, game 4 would also have been <em>impossible</em> because the Elf showed you 15 blue cubes at once. If you add up the IDs of the games that would have been possible, you get <code><em>8</em></code>.</p>
<p>Determine which games would have been possible if the bag had been loaded with only 12 red cubes, 13 green cubes, and 14 blue cubes. <em>What is the sum of the IDs of those games?</em></p>
</article>
<p>Your puzzle answer was <code>2593</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>The Elf says they've stopped producing snow because they aren't getting any <em>water</em>! He isn't sure why the water stopped; however, he can show you how to get to the water source to check it out for yourself. It's just up ahead!</p>
<p>As you continue your walk, the Elf poses a second question: in each game you played, what is the <em>fewest number of cubes of each color</em> that could have been in the bag to make the game possible?</p>
<p>Again consider the example games from earlier:</p>
<pre><code>Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
</code></pre>
<ul>
<li>In game 1, the game could have been played with as few as 4 red, 2 green, and 6 blue cubes. If any color had even one fewer cube, the game would have been impossible.</li>
<li>Game 2 could have been played with a minimum of 1 red, 3 green, and 4 blue cubes.<li>
<li>Game 3 must have been played with at least 20 red, 13 green, and 6 blue cubes.</li>
<li>Game 4 required at least 14 red, 3 green, and 15 blue cubes.</li>
<li>Game 5 needed no fewer than 6 red, 3 green, and 2 blue cubes in the bag.</li>
</ul>
<p>The <em>power</em> of a set of cubes is equal to the numbers of red, green, and blue cubes multiplied together. The power of the minimum set of cubes in game 1 is <code>48</code>. In games 2-5 it was <code>12</code>, <code>1560</code>, <code>630</code>, and <code>36</code>, respectively. Adding up these five powers produces the sum <code><em>2286</em></code>.</p>
<p>For each game, find the minimum set of cubes that must have been present. <em>What is the sum of the power of these sets?</em></p>
</article>
<p>Your puzzle answer was <code>54699</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
<p>At this point, you should <a href="index.html">return to your Advent calendar</a> and try another puzzle.</p>
<p>If you still want to see it, you can <a href="day02.txt" target="_blank">get your puzzle input</a>.</p>
<p>You can also <span class="share">[Share<span class="share-content">on
<a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Cube+Conundrum%22+%2D+Day+2+%2D+Advent+of+Code+2023&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2023%2Fday%2F2&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
<a href="javascript:void(0);" onclick="var ms; try{ms=localStorage.getItem('mastodon.server')}finally{} if(typeof ms!=='string')ms=''; ms=prompt('Mastodon Server?',ms); if(typeof ms==='string' && ms.length){this.href='https://'+ms+'/share?text=I%27ve+completed+%22Cube+Conundrum%22+%2D+Day+2+%2D+Advent+of+Code+2023+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2023%2Fday%2F2';try{localStorage.setItem('mastodon.server',ms);}finally{}}else{return false;}" target="_blank">Mastodon</a
></span>]</span> this puzzle.</p>
</main>
</body>
</html>
3 changes: 1 addition & 2 deletions src/2023/day02.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ export function part1(input) {
export function part2(input) {
const games = parse(input);
const powers = games.map(({ rounds }) => {
const dice = rounds.flat();
const max = ['red', 'blue', 'green'].map(c => {
const counts = dice.filter(({ color }) => color === c);
const counts = rounds.flat().filter(({ color }) => color === c);
return Math.max(...counts.map(({ count }) => count), 0);
});
return max[0] * max[1] * max[2];
Expand Down
4 changes: 2 additions & 2 deletions src/2023/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=<
<main>
<article>
<p>From here, you can access all of the events (and the corresponding puzzles, leaderboards, stats, etc) ever run on Advent of Code:</p>
<div class="eventlist-event"><a href="../2023/index.html">[2023]</a> <span class="star-count"> 2*</span> <a href="/2023/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a></div>
<div class="eventlist-event"><a href="../2023/index.html">[2023]</a> <span class="star-count"> 4*</span> <a href="/2023/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a></div>
<div class="eventlist-event"><a href="../2022/index.html">[2022]</a> <span class="star-count">50*</span> <a href="/2022/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a></div>
<div class="eventlist-event"><a href="../2021/index.html">[2021]</a> <span class="star-count">50*</span> <a href="/2021/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a></div>
<div class="eventlist-event"><a href="../2020/index.html">[2020]</a> <span class="star-count">50*</span> <a href="/2020/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a></div>
Expand All @@ -41,7 +41,7 @@ <h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=<
<div class="eventlist-event"><a href="../2017/index.html">[2017]</a> <span class="star-count">50*</span> <a href="/2017/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a></div>
<div class="eventlist-event"><a href="../2016/index.html">[2016]</a> <span class="star-count">50*</span> <a href="/2016/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a></div>
<div class="eventlist-event"><a href="../2015/index.html">[2015]</a> <span class="star-count">50*</span> <a href="/2015/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a></div>
<p>Total stars: <span class="star-count">402*</span></article>
<p>Total stars: <span class="star-count">404*</span></article>
</main>
</body>
</html>
16 changes: 9 additions & 7 deletions src/2023/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ <h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=<
<main>
<style>
.calendar .calendar-color-n { color:#9b715b; }
.calendar .calendar-color-w { color:#ffffff; }
.calendar .calendar-color-y { color:#ffff66; text-shadow:0 0 5px #ffff66, 0 0 10px #ffff66; }
.calendar .calendar-color-l { color:#ccccff; }
</style>
<pre class="calendar"><span aria-hidden="true" class=""> </span>
<span aria-hidden="true" class=""> </span>
Expand All @@ -55,14 +57,13 @@ <h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=<
<span aria-hidden="true" class=""> </span>
<span aria-hidden="true" class=""> </span>
<span aria-hidden="true" class=""> </span>
<span aria-hidden="true" class=""> </span>
<span aria-hidden="true" class=""> </span>
<span aria-hidden="true" class="calendar-day2"> <span class="calendar-color-n">----@</span> * <span class="calendar-day"> 2</span><span id="calendar-countdown"></span><script>
<span aria-hidden="true" class=""> <span class="calendar-color-w">'</span> <span class="calendar-color-l">-</span> </span>
<span aria-hidden="true" class="calendar-day3"> <span class="calendar-color-w">'</span> <span class="calendar-color-w">.</span> <span class="calendar-color-l">-</span> <span class="calendar-color-l">-</span> * <span class="calendar-color-w">.</span> <span class="calendar-day"> 3</span><span id="calendar-countdown"></span><script>
(function(){
var countdown = document.getElementById("calendar-countdown");
if (!countdown) return;
var server_eta = 45330;
var key = "2023-2-"+server_eta;
var server_eta = 74251;
var key = "2023-3-"+server_eta;
var now = Math.floor(new Date().getTime()/1000);
var target = server_eta + now;
if (sessionStorage) {
Expand All @@ -85,8 +86,8 @@ <h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=<
countdown.textContent = "";

var a = document.createElement("a");
a[String.fromCharCode(104,114,101,102)] = "/2023" + String.fromCharCode(47,100,97,121,47) + "2";
a.className = "calendar-day2 calendar-day-new";
a[String.fromCharCode(104,114,101,102)] = "/2023" + String.fromCharCode(47,100,97,121,47) + "3";
a.className = "calendar-day3 calendar-day-new";
var span = countdown.parentNode;
while (span.firstChild) {
a.appendChild(span.firstChild);
Expand All @@ -108,6 +109,7 @@ <h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=<
update_countdown();
})();
</script></span>
<a aria-label="Day 2, two stars" href="day02.html" class="calendar-day2 calendar-verycomplete"> <span class="calendar-color-n">----@</span> <span class="calendar-color-w">'''..</span><span class="calendar-color-y">*</span><span class="calendar-color-w">......'''</span> <span class="calendar-day"> 2</span> <span class="calendar-mark-complete">*</span><span class="calendar-mark-verycomplete">*</span></a>
<a aria-label="Day 1, two stars" href="day01.html" class="calendar-day1 calendar-verycomplete"> <span class="calendar-color-y">*</span> <span class="calendar-color-n">!</span> <span class="calendar-color-n">/^\</span> <span class="calendar-day"> 1</span> <span class="calendar-mark-complete">*</span><span class="calendar-mark-verycomplete">*</span></a>
</pre>
</main>
Expand Down
391 changes: 265 additions & 126 deletions src/2023/leaderboard.html

Large diffs are not rendered by default.

0 comments on commit 152578d

Please sign in to comment.