solve day 1, part 2
This commit is contained in:
parent
3ce05f3b1a
commit
1090cdbd82
@ -87,10 +87,10 @@ on Mastodon.
|
||||
|
||||
-->
|
||||
<body>
|
||||
<header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2025/about">[About]</a></li><li><a href="/2025/events">[Events]</a></li><li><a href="/2025/shop">[Shop]</a></li><li><a href="/2025/settings">[Settings]</a></li><li><a href="/2025/auth/logout">[Log Out]</a></li></ul></nav><div class="user">buhman</div></div><div><h1 class="title-event"> <span class="title-event-wrap">/*</span><a href="/2025">2025</a><span class="title-event-wrap">*/</span></h1><nav><ul><li><a href="/2025">[Calendar]</a></li><li><a href="/2025/support">[AoC++]</a></li><li><a href="/2025/sponsors">[Sponsors]</a></li><li><a href="/2025/leaderboard/private">[Leaderboards]</a></li><li><a href="/2025/stats">[Stats]</a></li></ul></nav></div></header>
|
||||
<header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2025/about">[About]</a></li><li><a href="/2025/events">[Events]</a></li><li><a href="/2025/shop">[Shop]</a></li><li><a href="/2025/settings">[Settings]</a></li><li><a href="/2025/auth/logout">[Log Out]</a></li></ul></nav><div class="user">buhman <span class="star-count">2*</span></div></div><div><h1 class="title-event"> <span class="title-event-wrap">int y=</span><a href="/2025">2025</a><span class="title-event-wrap">;</span></h1><nav><ul><li><a href="/2025">[Calendar]</a></li><li><a href="/2025/support">[AoC++]</a></li><li><a href="/2025/sponsors">[Sponsors]</a></li><li><a href="/2025/leaderboard/private">[Leaderboards]</a></li><li><a href="/2025/stats">[Stats]</a></li></ul></nav></div></header>
|
||||
|
||||
<div id="sidebar">
|
||||
<div id="sponsor"><div class="quiet">Our <a href="/2025/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="/2025/sponsors/redirect?url=https%3A%2F%2Fcoderabbit%2Elink%2Fadventofcode" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">CodeRabbit</a> - Cut Code Review Time and Bugs in Half</div></div>
|
||||
<div id="sponsor"><div class="quiet">Our <a href="/2025/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="/2025/sponsors/redirect?url=https%3A%2F%2Foptiver%2Ecom%2F" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Optiver</a> - Markets never stand still, and neither do our solutions. Our engineers build and refine systems powering millions of trades a day. Finished today's challenge? Find your next one here.</div></div>
|
||||
</div><!--/sidebar-->
|
||||
|
||||
<main>
|
||||
@ -137,12 +137,35 @@ L82
|
||||
<p>Because the dial points at <code>0</code> a total of three times during this process, the password in this example is <code><em>3</em></code>.</p>
|
||||
<p>Analyze the rotations in your attached document. <em>What's the actual password to open the door?</em></p>
|
||||
</article>
|
||||
<p>To begin, <a href="1/input" target="_blank">get your puzzle input</a>.</p>
|
||||
<form method="post" action="1/answer"><input type="hidden" name="level" value="1"/><p>Answer: <input type="text" name="answer" autocomplete="off"/> <input type="submit" value="[Submit]"/></p></form>
|
||||
<p>Your puzzle answer was <code>1011</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>You're sure that's the right password, but the door won't open. You knock, but nobody answers. You build a snowman while you think.</p>
|
||||
<p>As you're rolling the snowballs for your snowman, you find another security document that must have fallen into the snow:</p>
|
||||
<p>"Due to newer security protocols, please use <em>password method <span title="You should have seen the chaos when the Elves overflowed their 32-bit password method counter.">0x434C49434B</span></em> until further notice."</p>
|
||||
<p>You remember from the training seminar that "method 0x434C49434B" means you're actually supposed to count the number of times <em>any click</em> causes the dial to point at <code>0</code>, regardless of whether it happens during a rotation or at the end of one.</p>
|
||||
<p>Following the same rotations as in the above example, the dial points at zero a few extra times during its rotations:</p>
|
||||
<ul>
|
||||
<li>The dial starts by pointing at <code>50</code>.</li>
|
||||
<li>The dial is rotated <code>L68</code> to point at <code>82</code>; during this rotation, it points at <code>0</code> <em>once</em>.</li>
|
||||
<li>The dial is rotated <code>L30</code> to point at <code>52</code>.</li>
|
||||
<li>The dial is rotated <code>R48</code> to point at <code><em>0</em></code>.</li>
|
||||
<li>The dial is rotated <code>L5</code> to point at <code>95</code>.</li>
|
||||
<li>The dial is rotated <code>R60</code> to point at <code>55</code>; during this rotation, it points at <code>0</code> <em>once</em>.</li>
|
||||
<li>The dial is rotated <code>L55</code> to point at <code><em>0</em></code>.</li>
|
||||
<li>The dial is rotated <code>L1</code> to point at <code>99</code>.</li>
|
||||
<li>The dial is rotated <code>L99</code> to point at <code><em>0</em></code>.</li>
|
||||
<li>The dial is rotated <code>R14</code> to point at <code>14</code>.</li>
|
||||
<li>The dial is rotated <code>L82</code> to point at <code>32</code>; during this rotation, it points at <code>0</code> <em>once</em>.</li>
|
||||
</ul>
|
||||
<p>In this example, the dial points at <code>0</code> three times at the end of a rotation, plus three more times during a rotation. So, in this example, the new password would be <code><em>6</em></code>.</p>
|
||||
<p>Be careful: if the dial were pointing at <code>50</code>, a single rotation like <code>R1000</code> would cause the dial to point at <code>0</code> ten times before returning back to <code>50</code>!</p>
|
||||
<p>Using password method 0x434C49434B, <em>what is the password to open the door?</em></p>
|
||||
</article>
|
||||
<p>Your puzzle answer was <code>5937</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="/2025">return to your Advent calendar</a> and try another puzzle.</p>
|
||||
<p>If you still want to see it, you can <a href="1/input" target="_blank">get your puzzle input</a>.</p>
|
||||
<p>You can also <span class="share">[Share<span class="share-content">on
|
||||
<a href="https://bsky.app/intent/compose?text=%22Secret+Entrance%22+%2D+Day+1+%2D+Advent+of+Code+2025+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2025%2Fday%2F1" target="_blank">Bluesky</a>
|
||||
<a href="https://twitter.com/intent/tweet?text=%22Secret+Entrance%22+%2D+Day+1+%2D+Advent+of+Code+2025&url=https%3A%2F%2Fadventofcode%2Ecom%2F2025%2Fday%2F1&related=ericwastl&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=%22Secret+Entrance%22+%2D+Day+1+%2D+Advent+of+Code+2025+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2025%2Fday%2F1';try{localStorage.setItem('mastodon.server',ms);}finally{}}else{return false;}" target="_blank">Mastodon</a
|
||||
<a href="https://bsky.app/intent/compose?text=I%27ve+completed+%22Secret+Entrance%22+%2D+Day+1+%2D+Advent+of+Code+2025+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2025%2Fday%2F1" target="_blank">Bluesky</a>
|
||||
<a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Secret+Entrance%22+%2D+Day+1+%2D+Advent+of+Code+2025&url=https%3A%2F%2Fadventofcode%2Ecom%2F2025%2Fday%2F1&related=ericwastl&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+%22Secret+Entrance%22+%2D+Day+1+%2D+Advent+of+Code+2025+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2025%2Fday%2F1';try{localStorage.setItem('mastodon.server',ms);}finally{}}else{return false;}" target="_blank">Mastodon</a
|
||||
></span>]</span> this puzzle.</p>
|
||||
</main>
|
||||
|
||||
|
||||
@ -93,11 +93,11 @@ int main()
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
int input_width;
|
||||
int input_length = puzzle_2025_01_input_size;
|
||||
uint texture_input = rectangularize_input(puzzle_2025_01_input_start,
|
||||
puzzle_2025_01_input_size,
|
||||
&input_width);
|
||||
int input_height = input_width;
|
||||
int input_length = puzzle_2025_01_input_size;
|
||||
|
||||
uint texture_framebuffer = make_texture(NULL,
|
||||
GL_RGBA32F,
|
||||
|
||||
@ -42,27 +42,34 @@ vec2 parse_integer(float ix)
|
||||
vec2 parse_direction(float ix)
|
||||
{
|
||||
float c = get_input(ix);
|
||||
float left = (c == ascii_l) ? 1.0 : 0.0;
|
||||
return vec2(ix + 1.0, left);
|
||||
float direction = (c == ascii_l) ? -1.0 : 1.0;
|
||||
return vec2(ix + 1.0, direction);
|
||||
}
|
||||
|
||||
vec2 simulate_movement(float ix, float position)
|
||||
vec3 simulate_movement(float ix, float position)
|
||||
{
|
||||
vec2 dir_result = parse_direction(ix);
|
||||
ix = dir_result.x;
|
||||
float left = dir_result.y;
|
||||
float direction = dir_result.y;
|
||||
|
||||
vec2 int_result = parse_integer(ix);
|
||||
ix = int_result.x;
|
||||
float number = int_result.y;
|
||||
|
||||
if (left == 1.0) {
|
||||
position = position - number;
|
||||
} else {
|
||||
position = position + number;
|
||||
float old_position = position;
|
||||
float crossings = floor(number / 100.0);
|
||||
position += direction * mod(number, 100.0);
|
||||
if (position < 0.0) {
|
||||
position += 100.0;
|
||||
crossings += float(old_position != 0.0);
|
||||
}
|
||||
position = mod(position, 100);
|
||||
return vec2(ix, position);
|
||||
if (position > 99.0) {
|
||||
position -= 100.0;
|
||||
crossings += float(position != 0.0);
|
||||
}
|
||||
crossings += float(position == 0.0);
|
||||
|
||||
return vec3(ix, position, crossings);
|
||||
}
|
||||
|
||||
void main()
|
||||
@ -70,16 +77,18 @@ void main()
|
||||
float ix = 0.0;
|
||||
float position = 50.0;
|
||||
float zeros = 0.0;
|
||||
float zero_crossings = 0.0;
|
||||
|
||||
while (ix < input_length) {
|
||||
vec2 result = simulate_movement(ix, position);
|
||||
vec3 result = simulate_movement(ix, position);
|
||||
ix = result.x;
|
||||
position = result.y;
|
||||
zero_crossings += result.z;
|
||||
|
||||
if (position == 0.0) {
|
||||
zeros += 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
fragment_color = vec4(position, zeros, 0, 0);
|
||||
fragment_color = vec4(zeros, zero_crossings, 0, 0);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user