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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Day04 do
  def part1(file) when is_binary(file), do: file |&gt; to_grid() |&gt; part1()
  def part1(%{} = grid), do: Enum.count(grid, &amp;accessible?(grid, &amp;1))

  def to_grid(file), do: file |&gt; Util.file_to_char_map() |&gt; Map.filter(fn {_, v} -&gt; v == ?@ end)
  def accessible?(grid, {pos, _}), do: Enum.count(adj(pos), &amp;(grid[&amp;1] == ?@)) &lt; 4
  def adj({x, y}), do: for(dx &lt;- -1..1, dy &lt;- -1..1, {dx, dy} != {0, 0}, do: {x + dx, y + dy})

  def part2(file) do
    to_grid(file)
    |&gt; Stream.unfold(fn grid -&gt;
      {count, new_grid} = remove_accessible(grid)
      if count &gt; 0, do: {count, new_grid}, else: nil
    end)
    |&gt; Enum.sum()
  end

  def remove_accessible(grid) do
    removable = grid |&gt; Enum.filter(&amp;accessible?(grid, &amp;1)) |&gt; Enum.map(&amp;elem(&amp;1, 0))
    {length(removable), Enum.reduce(removable, grid, &amp;Map.delete(&amp;2, &amp;1))}
  end
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="379900" 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-2025-day-4/73543/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-379900" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="379900"
                     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>