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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>TIL Function.identity. Thanks!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="234211" data-batch-url="/posts/batch_likers">
                        1
                      </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-2021-day-5/44266/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-234211" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="234211"
                     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 #21"></div>
  </section>
</div>
    <div class="postbit" id="234225" data-post-id="234225">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>part 1:</p>
<p><a href="https://github.com/rugyoga/aoc2021/blob/main/day5.exs" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/rugyoga/aoc2021/blob/main/day5.exs</a></p>
<p>part 2:</p>
<p><a href="https://github.com/rugyoga/aoc2021/blob/main/day5b.exs" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/rugyoga/aoc2021/blob/main/day5b.exs</a></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="234225" 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-2021-day-5/44266/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-234225" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="234225"
                     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 #22"></div>
  </section>
</div>
    <div class="postbit" id="234240" data-post-id="234240">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="deadbeef" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  deadbeef
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>My solution. Think it’s pretty similar to others.<br>
Believe my diagonal approach is too naive, but happened to work for the input.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Advent.Y2021.D05 do
  @spec part_one(Enumerable.t()) :: non_neg_integer()
  def part_one(input) do
    input
    |&gt; parse_input()
    |&gt; Stream.filter(fn {{x1, y1}, {x2, y2}} -&gt;
      x1 == x2 || y1 == y2
    end)
    |&gt; count_overlapping_coords()
  end

  @spec part_two(Enumerable.t()) :: non_neg_integer()
  def part_two(input) do
    input
    |&gt; parse_input()
    |&gt; count_overlapping_coords()
  end

  @spec parse_input(Enumerable.t()) :: Enumerable.t()
  defp parse_input(input) do
    Stream.map(input, fn line -&gt;
      [x1, y1, x2, y2] =
        Regex.run(~r/(\d+),(\d+)\s+\-&gt;\s+(\d+),(\d+)/, line, capture: :all_but_first)
        |&gt; Enum.map(&amp;String.to_integer/1)

      {{x1, y1}, {x2, y2}}
    end)
  end

  @spec count_overlapping_coords(Enumerable.t()) :: non_neg_integer()
  defp count_overlapping_coords(coords) do
    coords
    |&gt; Stream.flat_map(fn
      {{x, y1}, {x, y2}} -&gt; Enum.map(y1..y2, fn y -&gt; {x, y} end)
      {{x1, y}, {x2, y}} -&gt; Enum.map(x1..x2, fn x -&gt; {x, y} end)
      {{x1, y1}, {x2, y2}} -&gt; Enum.zip(x1..x2, y1..y2)
    end)
    |&gt; Enum.frequencies()
    |&gt; Enum.count(fn {_, count} -&gt; count &gt; 1 end)
  end
end

input =
  File.stream!("d05_input.txt")
  |&gt; Stream.map(&amp;String.trim/1)

IO.inspect(Advent.Y2021.D05.part_one(input))
IO.inspect(Advent.Y2021.D05.part_two(input))
</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="234240" 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-2021-day-5/44266/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-234240" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="234240"
                     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 #23"></div>
  </section>
</div>
    <div class="postbit" id="234723" data-post-id="234723">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="raumfisch" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  raumfisch
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>A bit late, but my solution for day 5:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Advent5 do

  def calc do
    {:ok, contents} = File.read("input5.txt")
    moves = contents |&gt; String.split("\n", trim: true) |&gt; Enum.map(&amp;pars_move(&amp;1))
    hight_points = build_map_points(moves, []) |&gt; Enum.frequencies() |&gt; Enum.to_list() |&gt; Enum.filter(fn {_,hight} -&gt; hight &gt;= 2 end)
    Enum.count(hight_points)
  end

  def build_map_points([],points), do: points
  def build_map_points([move|tail],points), do: build_map_points(tail, points ++ build_path(move))

  def pars_move(move) do
    move |&gt; String.replace(" ", "") |&gt; String.split("-&gt;", trim: true) |&gt; Enum.map(fn cord -&gt;
      [x,y] = String.split(cord, ",")
      {ix,_} = Integer.parse(x)
      {iy,_} = Integer.parse(y)
      {ix,iy}
    end)
  end

  def build_path([{xs,ys},{xe,ye}]) when xs == xe ,do: Enum.to_list(ys..ye) |&gt; Enum.map(fn y -&gt; {xs,y} end)
  def build_path([{xs,ys},{xe,ye}]) when ys == ye ,do: Enum.to_list(xs..xe) |&gt; Enum.map(fn x -&gt; {x,ys} end)
  def build_path([{xs,ys},{xe,ye}]) ,do: Enum.zip(Enum.to_list(xs..xe), Enum.to_list(ys..ye))

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="234723" 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-2021-day-5/44266/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-234723" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="234723"
                     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 #24"></div>
  </section>
</div>
    <div class="postbit" id="234777" data-post-id="234777">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I just uploaded Jose’s day 5 stream summary: <a href="https://www.youtube.com/watch?v=K6SFEoRaTNE" rel="noopener nofollow ugc">https://www.youtube.com/watch?v=K6SFEoRaTNE</a>. Hope this summary could be of use for anyone. <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="234777" 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-2021-day-5/44266/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-234777" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="234777"
                     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>