<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="272373" data-post-id="272373">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="tfwright" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tfwright/120/20299_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  tfwright
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>For me this puzzle had the greatest divergence between complexity and difficulty. It was fairly easy to reason about what to do but of course the first naive solution that solved for the test input by tracking the content of every node  was far too slow for the actual input.</p>
<p>I solved part 1 after realizing I only needed to track the ranges of intersection on a single line, and then I used that same trick in part 2 to avoid having to check every single point since I could get the intersection for the current x value and then skip to the end of the y range. Took less than 3 secs on my laptop.</p>
<aside class="onebox githubgist" data-onebox-src="https://gist.github.com/tfwright/aa9f059bd3b23d8da814a1c605cef4bb">
  <header class="source">

      <a href="https://gist.github.com/tfwright/aa9f059bd3b23d8da814a1c605cef4bb" target="_blank" rel="noopener nofollow ugc">gist.github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://gist.github.com/tfwright/aa9f059bd3b23d8da814a1c605cef4bb" target="_blank" rel="noopener nofollow ugc">https://gist.github.com/tfwright/aa9f059bd3b23d8da814a1c605cef4bb</a></h4>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="272373" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/advent-of-code-2022-day-15/52552/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-272373" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="272373"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="272713" data-post-id="272713">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="al2o3cr" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/120/3457_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  al2o3cr
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Part 1 was a straightforward “generate sets representing coverage at the target coordinate and union them all together” task, but that would have created <em>massive</em> sets for part 2.</p>
<p>Part 2 was saved by the <code>0..4_000_000</code> bound - instead of creating a list of all the positions that are covered, the solution subtracts a range for each sensor <em>from</em> the whole range. This removes the need to create a list/set/etc with 4m elements in favor of a maximum of <code>O(sensors)</code> ranges per Y coordinate.</p>
<p>Each Y coordinate is computed entirely separately, so the problem is exactly the sort of “embarrassingly parallel” situation that <code>Task.async_stream</code> helps with. It could stand some tuning (maybe grouping batches of Y-coordinates together?), as it only manages to saturate 2 CPUs on my laptop.</p>
<aside class="onebox githubgist" data-onebox-src="https://gist.github.com/al2o3cr/387c23a1fb457127ba9bec0af29acc0e">
  <header class="source">

      <a href="https://gist.github.com/al2o3cr/387c23a1fb457127ba9bec0af29acc0e" target="_blank" rel="noopener nofollow">gist.github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://gist.github.com/al2o3cr/387c23a1fb457127ba9bec0af29acc0e" target="_blank" rel="noopener nofollow">https://gist.github.com/al2o3cr/387c23a1fb457127ba9bec0af29acc0e</a></h4>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="272713" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/advent-of-code-2022-day-15/52552/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-272713" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="272713"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>