Skip to content

Commit

Permalink
day 1
Browse files Browse the repository at this point in the history
  • Loading branch information
shahata committed Dec 1, 2023
1 parent cfee894 commit c0a2490
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 23 deletions.
70 changes: 70 additions & 0 deletions src/2023/day01.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8" />
<title>Day 1 - 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 1: Trebuchet?! ---</h2><p>Something is wrong with global snow production, and you've been selected to take a look. The Elves have even given you a map; on it, they've used stars to mark the top fifty locations that are likely to be having problems.</p>
<p>You've been doing this long enough to know that to restore snow operations, you need to check all <em class="star">fifty stars</em> by December 25th.</p>
<p>Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants <em class="star">one star</em>. Good luck!</p>
<p>You try to ask why they can't just use a <a href="/2015/day/1">weather machine</a> ("not powerful enough") and where they're even sending you ("the sky") and why your map looks mostly blank ("you sure ask a lot of questions") <span title="My hope is that this abomination of a run-on sentence somehow conveys the chaos of being hastily loaded into a trebuchet.">and</span> hang on did you just say the sky ("of course, where do you think snow comes from") when you realize that the Elves are already loading you into a <a href="https://en.wikipedia.org/wiki/Trebuchet" target="_blank">trebuchet</a> ("please hold still, we need to strap you in").</p>
<p>As they're making the final adjustments, they discover that their calibration document (your puzzle input) has been <em>amended</em> by a very young Elf who was apparently just excited to show off her art skills. Consequently, the Elves are having trouble reading the values on the document.</p>
<p>The newly-improved calibration document consists of lines of text; each line originally contained a specific <em>calibration value</em> that the Elves now need to recover. On each line, the calibration value can be found by combining the <em>first digit</em> and the <em>last digit</em> (in that order) to form a single <em>two-digit number</em>.</p>
<p>For example:</p>
<pre><code>1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet
</code></pre>
<p>In this example, the calibration values of these four lines are <code>12</code>, <code>38</code>, <code>15</code>, and <code>77</code>. Adding these together produces <code><em>142</em></code>.</p>
<p>Consider your entire calibration document. <em>What is the sum of all of the calibration values?</em></p>
</article>
<p>Your puzzle answer was <code>54953</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>Your calculation isn't quite right. It looks like some of the digits are actually <em>spelled out with letters</em>: <code>one</code>, <code>two</code>, <code>three</code>, <code>four</code>, <code>five</code>, <code>six</code>, <code>seven</code>, <code>eight</code>, and <code>nine</code> <em>also</em> count as valid "digits".</p>
<p>Equipped with this new information, you now need to find the real first and last digit on each line. For example:</p>
<pre><code>two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen
</code></pre>
<p>In this example, the calibration values are <code>29</code>, <code>83</code>, <code>13</code>, <code>24</code>, <code>42</code>, <code>14</code>, and <code>76</code>. Adding these together produces <code><em>281</em></code>.</p>
<p><em>What is the sum of all of the calibration values?</em></p>
</article>
<p>Your puzzle answer was <code>53868</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="day01.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+%22Trebuchet%3F%21%22+%2D+Day+1+%2D+Advent+of+Code+2023&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2023%2Fday%2F1&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+%22Trebuchet%3F%21%22+%2D+Day+1+%2D+Advent+of+Code+2023+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2023%2Fday%2F1';try{localStorage.setItem('mastodon.server',ms);}finally{}}else{return false;}" target="_blank">Mastodon</a
></span>]</span> this puzzle.</p>
</main>
</body>
</html>
16 changes: 7 additions & 9 deletions src/2023/day01.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const rs = s => s.split('').reverse().join('');

export function part1(input) {
const lines = input.split('\n');
const numbers = lines.map(line => {
const first = +line.match(/[0-9]/).at(0);
const last = +rs(line).match(/[0-9]/).at(0);
const first = +line.match(/[0-9]/g).at(0);
const last = +line.match(/[0-9]/g).at(-1);
return first * 10 + last;
});
return numbers.reduce((a, b) => a + b, 0);
Expand All @@ -23,15 +21,15 @@ export function part2(input) {
'eight',
'nine',
];
const regex = new RegExp('[0-9]|' + letters.join('|'));
const regex2 = new RegExp('[0-9]|' + rs(letters.join('|')));
const reverse = s => s.split('').reverse().join('');
const regex = new RegExp(`[0-9]|${letters.join('|')}`);
const regex2 = new RegExp(`[0-9]|${reverse(letters.join('|'))}`);
const lines = input.split('\n');
const numbers = lines.map(line => {
const first = line.match(regex).at(0);
const last = rs(line).match(regex2).at(0);

const last = reverse(reverse(line).match(regex2).at(0));
const a = Number.isNaN(+first) ? letters.indexOf(first) : +first;
const b = Number.isNaN(+last) ? letters.indexOf(rs(last)) : +last;
const b = Number.isNaN(+last) ? letters.indexOf(last) : +last;
return a * 10 + b;
});
return numbers.reduce((a, b) => a + b, 0);
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> <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"> 2*</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">400*</span></article>
<p>Total stars: <span class="star-count">402*</span></article>
</main>
</body>
</html>
19 changes: 11 additions & 8 deletions src/2023/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ <h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=<
</div>
</header>
<main>
<p>The first puzzles will unlock on December 1st at midnight EST (UTC-5). See you then!</p>
<p>Also, starting this December, please <a href="/about#faq_ai_leaderboard">don't use AI to get on the global leaderboard</a>.</p><pre class="calendar"><span aria-hidden="true" class=""> </span>
<style>
.calendar .calendar-color-n { color:#9b715b; }
.calendar .calendar-color-y { color:#ffff66; text-shadow:0 0 5px #ffff66, 0 0 10px #ffff66; }
</style>
<pre class="calendar"><span aria-hidden="true" class=""> </span>
<span aria-hidden="true" class=""> </span>
<span aria-hidden="true" class=""> </span>
<span aria-hidden="true" class=""> </span>
Expand All @@ -54,13 +57,12 @@ <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="calendar-day1"> * <span class="calendar-day"> 1</span><span id="calendar-countdown"></span><script>
<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>
(function(){
var countdown = document.getElementById("calendar-countdown");
if (!countdown) return;
var server_eta = 193760;
var key = "2023-1-"+server_eta;
var server_eta = 45330;
var key = "2023-2-"+server_eta;
var now = Math.floor(new Date().getTime()/1000);
var target = server_eta + now;
if (sessionStorage) {
Expand All @@ -83,8 +85,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) + "1";
a.className = "calendar-day1 calendar-day-new";
a[String.fromCharCode(104,114,101,102)] = "/2023" + String.fromCharCode(47,100,97,121,47) + "2";
a.className = "calendar-day2 calendar-day-new";
var span = countdown.parentNode;
while (span.firstChild) {
a.appendChild(span.firstChild);
Expand All @@ -106,6 +108,7 @@ <h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">$year=<
update_countdown();
})();
</script></span>
<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>
</body>
Expand Down
214 changes: 210 additions & 4 deletions src/2023/leaderboard.html

Large diffs are not rendered by default.

0 comments on commit c0a2490

Please sign in to comment.