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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>At this rate, I might catch up. Here’s my first pass at part 1:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">#!/usr/bin/env elixir

defmodule Day10.Part1 do
  @ascii_adjustment 48
  @trail_head 0
  @destination 9
  @search_depth @destination

  defp parse(str) do
    [row | _rows] =
      rows =
      str
      |&gt; String.split("\n", trim: true)
      |&gt; Stream.map(&amp;to_charlist/1)
      |&gt; Enum.map(fn row -&gt;
        Enum.map(row, &amp;(&amp;1 - @ascii_adjustment))
      end)

    height = Enum.count(rows)
    length = Enum.count(row)

    trail_heads =
      for y &lt;- 0..(height - 1), x &lt;- 0..(length - 1) do
        {x, y}
      end
      |&gt; Enum.reduce(
        [],
        fn {x, y} = pos, trail_heads = acc -&gt;
          c = rows |&gt; Enum.at(y) |&gt; Enum.at(x)

          case c do
            @trail_head -&gt; [pos | trail_heads]
            _ -&gt; acc
          end
        end
      )

    %{
      map: %{
        height: height,
        length: length,
        rows: rows
      },
      trail_heads: trail_heads
    }
  end

  defp on_board?({x, y}, height, length) when x &lt; 0 or x &gt;= length or y &lt; 0 or y &gt;= height,
    do: false

  defp on_board?(_pair, _height, _length), do: true

  defp reachable_neighbors({x, y}, %{height: height, length: length, rows: rows}) do
    current_value = rows |&gt; Enum.at(y) |&gt; Enum.at(x)

    [{x + 1, y}, {x - 1, y}, {x, y + 1}, {x, y - 1}]
    |&gt; Enum.filter(fn {neighbor_x, neighbor_y} = pair -&gt;
      on_board?(pair, height, length) and
        (rows |&gt; Enum.at(neighbor_y) |&gt; Enum.at(neighbor_x)) - current_value == 1
    end)
  end

  defp reachable_destinations({x, y} = pos, %{rows: rows} = _map, 0 = _search_depth) do
    if rows |&gt; Enum.at(y) |&gt; Enum.at(x) == @destination, do: MapSet.new([pos]), else: MapSet.new()
  end

  defp reachable_destinations(pos, map, search_depth) do
    reachable_neighbors(pos, map)
    |&gt; Enum.reduce(
      MapSet.new(),
      fn neighbor, reachable_destinations -&gt;
        reachable_destinations(neighbor, map, search_depth - 1)
        |&gt; Enum.into(reachable_destinations)
      end
    )
  end

  defp unique_destination_count(trail_head, map, search_depth) do
    reachable_neighbors(trail_head, map)
    |&gt; Enum.reduce(
      MapSet.new(),
      fn neighbor, destinations_already_seen -&gt;
        reachable_destinations(neighbor, map, search_depth - 1)
        |&gt; Enum.into(destinations_already_seen)
      end
    )
    |&gt; Enum.count()
  end

  defp trail_head_scores(%{
         map: map,
         trail_heads: trail_heads
       }) do
    trail_heads
    |&gt; Enum.map(&amp;unique_destination_count(&amp;1, map, @search_depth))
    |&gt; Enum.sum()
  end

  def solve() do
    File.read!("10/input.txt")
    |&gt; parse()
    |&gt; trail_head_scores()
    |&gt; IO.puts()
  end
end

Day10.Part1.solve()
</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="349293" 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-2024-day-10/67999/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-349293" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349293"
                     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="349295" data-post-id="349295">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>solved part 2 first as well xD</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="349295" 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-2024-day-10/67999/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-349295" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349295"
                     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 #12"></div>
  </section>
</div>
    <div class="postbit" id="349296" data-post-id="349296">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Woo! Caught up.</p>
<p>Here’s my first pass at part 2. Found it to be simpler than part 1. I’m betting I could refactor my work there tho. In tackling part 2 I found some bits unnecessary due to the guarantees from stopping recursion at the search depth.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">#!/usr/bin/env elixir

defmodule Day10.Part1 do
  @ascii_adjustment 48
  @trail_head 0
  @destination 9
  @search_depth @destination

  defp parse(str) do
    [row | _rows] =
      rows =
      str
      |&gt; String.split("\n", trim: true)
      |&gt; Stream.map(&amp;to_charlist/1)
      |&gt; Enum.map(fn row -&gt;
        Enum.map(row, &amp;(&amp;1 - @ascii_adjustment))
      end)

    height = Enum.count(rows)
    length = Enum.count(row)

    trail_heads =
      for y &lt;- 0..(height - 1), x &lt;- 0..(length - 1) do
        {x, y}
      end
      |&gt; Enum.reduce(
        [],
        fn {x, y} = pos, trail_heads = acc -&gt;
          c = rows |&gt; Enum.at(y) |&gt; Enum.at(x)

          case c do
            @trail_head -&gt; [pos | trail_heads]
            _ -&gt; acc
          end
        end
      )

    %{
      map: %{
        height: height,
        length: length,
        rows: rows
      },
      trail_heads: trail_heads
    }
  end

  defp on_board?({x, y}, height, length) when x &lt; 0 or x &gt;= length or y &lt; 0 or y &gt;= height,
    do: false

  defp on_board?(_pair, _height, _length), do: true

  defp reachable_neighbors({x, y}, %{height: height, length: length, rows: rows}) do
    current_value = rows |&gt; Enum.at(y) |&gt; Enum.at(x)

    [{x + 1, y}, {x - 1, y}, {x, y + 1}, {x, y - 1}]
    |&gt; Enum.filter(fn {neighbor_x, neighbor_y} = pair -&gt;
      on_board?(pair, height, length) and
        (rows |&gt; Enum.at(neighbor_y) |&gt; Enum.at(neighbor_x)) - current_value == 1
    end)
  end

  defp reachable_destinations({x, y} = pos, %{rows: rows} = _map, 0 = _search_depth) do
    if rows |&gt; Enum.at(y) |&gt; Enum.at(x) == @destination, do: MapSet.new([pos]), else: MapSet.new()
  end

  defp reachable_destinations(pos, map, search_depth) do
    reachable_neighbors(pos, map)
    |&gt; Enum.reduce(
      MapSet.new(),
      fn neighbor, reachable_destinations -&gt;
        reachable_destinations(neighbor, map, search_depth - 1)
        |&gt; Enum.into(reachable_destinations)
      end
    )
  end

  defp unique_destination_count(trail_head, map, search_depth) do
    reachable_neighbors(trail_head, map)
    |&gt; Enum.reduce(
      MapSet.new(),
      fn neighbor, destinations_already_seen -&gt;
        reachable_destinations(neighbor, map, search_depth - 1)
        |&gt; Enum.into(destinations_already_seen)
      end
    )
    |&gt; Enum.count()
  end

  defp trail_head_scores(%{
         map: map,
         trail_heads: trail_heads
       }) do
    trail_heads
    |&gt; Enum.map(&amp;unique_destination_count(&amp;1, map, @search_depth))
    |&gt; Enum.sum()
  end

  def solve() do
    File.read!("10/input.txt")
    |&gt; parse()
    |&gt; trail_head_scores()
    |&gt; IO.puts()
  end
end

Day10.Part1.solve()
</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="349296" 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-2024-day-10/67999/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-349296" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349296"
                     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 #13"></div>
  </section>
</div>
    <div class="postbit" id="349305" data-post-id="349305">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I think thats the first day that i liked my solution. In my opinion very clean different than other days such as day 9 which i suffered a lot.</p>
<p><a href="https://github.com/newton-peixoto/advent-of-code/blob/main/2024/livebooks/day-10.livemd" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/newton-peixoto/advent-of-code/blob/main/2024/livebooks/day-10.livemd</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="349305" 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-2024-day-10/67999/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-349305" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349305"
                     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 #14"></div>
  </section>
</div>
    <div class="postbit" id="349308" data-post-id="349308">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>happy for now <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>part1: <a href="https://github.com/jarlah/advent_of_code/blob/master/lib/2024/day_10/Part1.ex#L60" rel="noopener nofollow ugc">https://github.com/jarlah/advent_of_code/blob/master/lib/2024/day_10/Part1.ex#L60</a><br>
part2: <a href="https://github.com/jarlah/advent_of_code/blob/master/lib/2024/day_10/Part2.ex#L58" rel="noopener nofollow ugc">https://github.com/jarlah/advent_of_code/blob/master/lib/2024/day_10/Part2.ex#L58</a></p>
<p>i actually sincerely feel that my code is readable and understandable. There is very little going on actually. Took me some time to understand the problem though. But when i had the requirements in my head things started to fall into place ..</p>
<p>the irony is that i started on making code to find all unique paths before i figured part1 was actually just to find the first path…</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="349308" 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-2024-day-10/67999/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-349308" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349308"
                     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 #15"></div>
  </section>
</div>
    <div class="postbit" id="349460" data-post-id="349460">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>As others I solved part 2 first without realizing it. Then it was a struggle until I finally re-read the instructions and realized I was only supposed to count unique destinations for each trailhead.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">require Grid

defmodule Aoc2024.Day10 do
  @moduledoc false

  def part1(file) do
    grid = get_input(file)

    grid
    |&gt; find_trailheads()
    |&gt; Enum.map(&amp;climb(grid, &amp;1))
    |&gt; List.flatten()
    |&gt; Enum.map(fn path -&gt;
      MapSet.to_list(path)
      |&gt; Enum.filter(fn {height, _} -&gt; height == 0 or height == 9 end)
    end)
    |&gt; Enum.uniq()
    |&gt; length()
  end

  def part2(file) do
    grid = get_input(file)

    grid
    |&gt; find_trailheads()
    |&gt; Enum.map(&amp;climb(grid, &amp;1))
    |&gt; List.flatten()
    |&gt; Enum.uniq()
    |&gt; length()
  end

  defp get_input(file) do
    File.read!(file)
    |&gt; Grid.new(&amp;String.to_integer/1)
  end

  defp find_trailheads(grid) do
    Grid.filter(grid, fn v -&gt; v == 0 end)
  end

  defp climb(grid, pos = {x, y}, path \\ MapSet.new()) do
    value = Grid.at(grid, pos)
    path = MapSet.put(path, {value, pos})

    if value == 9 do
      path
    else
      [{-1, 0}, {1, 0}, {0, -1}, {0, 1}]
      |&gt; Enum.reduce([], fn {dx, dy}, good -&gt;
        next = {x + dx, y + dy}

        if Grid.at(grid, next) == value + 1 and not MapSet.member?(path, {value + 1, next}) do
          [next | good]
        else
          good
        end
      end)
      |&gt; Enum.map(fn next -&gt;
        climb(grid, next, path)
      end)
    end
  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="349460" 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-2024-day-10/67999/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-349460" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349460"
                     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 #16"></div>
  </section>
</div>
    <div class="postbit" id="349490" data-post-id="349490">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<pre data-code-wrap="elixir"><code class="lang-elixir">Set up the map in 3633 µs
Part 1: 531
Job done in 2122 µs
Part 2: 1210
Job done in 968 µs
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">#!/usr/bin/env elixir

# AoC 2024. day 10.

###########################################################
# Part 1

defmodule Part1 do
  def seek(_map, 9, row, col, pos), do: MapSet.put(pos, {row,col})
  def seek(map, curr, row, col, pos) do
    next = map[{row-1,col}]
    pos = (if next == curr+1, do: seek(map, next, row-1, col, pos), else: pos)
    next = map[{row,col+1}]
    pos = (if next == curr+1, do: seek(map, next, row, col+1, pos), else: pos)
    next = map[{row+1,col}]
    pos = (if next == curr+1, do: seek(map, next, row+1, col, pos), else: pos)
    next = map[{row,col-1}]
    (if next == curr+1, do: seek(map, next, row, col-1, pos), else: pos)
  end
end

start = System.monotonic_time(:microsecond)
map = File.stream!("../day10.txt")
  |&gt; Stream.with_index(1)
  |&gt; Enum.reduce(%{}, fn {line, row}, map -&gt;
    line
    |&gt; String.trim_trailing()
    |&gt; String.codepoints()
    |&gt; Enum.with_index(1)
    |&gt; Enum.reduce(map, fn {c, col}, map -&gt; Map.put(map, {row, col}, (if c == ".", do: -1, else: String.to_integer(c))) end)
  end)
elapsed = System.monotonic_time(:microsecond) - start
IO.puts "Set up the map in #{elapsed} µs"

start = System.monotonic_time(:microsecond)
map
|&gt; Enum.filter(fn {_k,v} -&gt; v == 0 end)
|&gt; Enum.map(fn {k,_v} -&gt; k end)
|&gt; Enum.reduce(0, fn {row,col}, n -&gt; n+MapSet.size(Part1.seek(map, 0, row, col, MapSet.new())) end)
|&gt; IO.inspect(label: "Part 1")
elapsed = System.monotonic_time(:microsecond) - start
IO.puts "Job done in #{elapsed} µs"


###########################################################
# Part 2

defmodule Part2 do
  def seek(_map, 9, _row, _col), do: 1
  def seek(map, curr, row, col) do
    next = map[{row-1,col}]
    n = (if next == curr+1, do: seek(map, next, row-1, col), else: 0)
    next = map[{row,col+1}]
    n = n + (if next == curr+1, do: seek(map, next, row, col+1), else: 0)
    next = map[{row+1,col}]
    n = n + (if next == curr+1, do: seek(map, next, row+1, col), else: 0)
    next = map[{row,col-1}]
    n + (if next == curr+1, do: seek(map, next, row, col-1), else: 0)
  end
end

start = System.monotonic_time(:microsecond)
map
|&gt; Enum.filter(fn {_k,v} -&gt; v == 0 end)
|&gt; Enum.map(fn {k,_v} -&gt; k end)
|&gt; Enum.reduce(0, fn {row,col}, n -&gt; n+Part2.seek(map, 0, row, col) end)
|&gt; IO.inspect(label: "Part 2")
elapsed = System.monotonic_time(:microsecond) - start
IO.puts "Job done in #{elapsed} µs"
</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="349490" 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-2024-day-10/67999/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-349490" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349490"
                     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 #17"></div>
  </section>
</div>
    <div class="postbit" id="349491" data-post-id="349491">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Exactly the same for me <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" 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="349491" 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-2024-day-10/67999/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-349491" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349491"
                     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 #18"></div>
  </section>
</div>
    <div class="postbit" id="349517" data-post-id="349517">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<blockquote>
<p>I actually ended up solving part 2 first</p>
</blockquote>
<p>Same. <img src="https://forum.elixirforum.com/images/emoji/apple/joy.png?v=15" title=":joy:" class="emoji" alt=":joy:" loading="lazy" width="20" height="20">  I misinterpreted part one and as I fixed it and got to part 2 I saw 81 and was like ‘wait, I saw that’.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Aoc2024.Solutions.Y24.Day10 do
  alias AoC.Input

  def parse(input, part) do
    input
    |&gt; Input.stream!(trim: true)
    |&gt; Stream.with_index()
    |&gt; Enum.reduce({[], %{}}, fn {line, x}, {trailheads, map} -&gt;
      line
      |&gt; String.codepoints()
      |&gt; Stream.with_index()
      |&gt; Enum.reduce({trailheads, map}, fn
        {e, y}, {trailheads, map} -&gt;
          case String.to_integer(e) do
            0 -&gt; {[{x, y} | trailheads], map}
            n -&gt; {trailheads, Map.put(map, {x, y}, n)}
          end
      end)
    end)
    |&gt; Tuple.append(if(part == :part_one, do: MapSet.new(), else: 0))
  end

  def part_one({trailheads, map, init}) do
    solver(trailheads, map, init, 0)
  end

  def part_two({trailheads, map, init}) do
    solver(trailheads, map, init, 0)
  end

  defp solver([], _map, _init, acc), do: acc

  defp solver([{x, y} | rest], map, init, acc) when is_map(init) do
    result = follow_trails(x, y, map, 0, init)
    solver(rest, map, init, acc + MapSet.size(result))
  end

  defp solver([{x, y} | rest], map, init, acc) do
    result = follow_trails(x, y, map, 0, init)
    solver(rest, map, init, acc + result)
  end

  defp follow_trails(x, y, map, n, acc) do
    [{x + 1, y}, {x - 1, y}, {x, y + 1}, {x, y - 1}]
    |&gt; Enum.reduce([], fn point, acc -&gt;
      value = Map.get(map, point)
      if value == n + 1, do: [{point, value} | acc], else: acc
    end)
    |&gt; Enum.reduce(acc, fn
      {point, 9}, acc -&gt;
        if is_map(acc), do: MapSet.put(acc, point), else: acc + 1

      {{next_x, next_y}, _value}, acc -&gt;
        follow_trails(next_x, next_y, map, n + 1, acc)
    end)
  end
end
</code></pre>
<p>In the end I bundled them together, only switching/checking the initial variable. Not good design wise but I like the elegance. <img src="https://forum.elixirforum.com/images/emoji/apple/cowboy_hat_face.png?v=15" title=":cowboy_hat_face:" class="emoji" alt=":cowboy_hat_face:" loading="lazy" width="20" height="20"></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Solution for 2024 day 10
part_one: 760 in 19.68ms
part_two: 1764 in 6.62ms
</code></pre>
<p><a class="mention" href="/u/lud" rel="nofollow">@lud</a> Also, I have a feeling the benchmarking is not right for part 2? I’m not sure, <a href="https://forum.elixirforum.com/t/advent-of-code-2024-day-8/67956/13" rel="nofollow">here</a> is reference for this also.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="349517" 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-2024-day-10/67999/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-349517" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349517"
                     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 #19"></div>
  </section>
</div>
    <div class="postbit" id="349549" data-post-id="349549">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="ken-kost" data-post="20" data-topic="67999">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ken-kost/48/40209_2.png" class="avatar"> ken-kost:</div>
<blockquote>
<pre data-code-wrap="elixir"><code class="lang-elixir">Solution for 2024 day 10
part_one: 760 in 19.68ms
part_two: 1764 in 6.62ms
</code></pre>
</blockquote>
</aside>
<p>Those times are derived from only one call. It can be because the system is “cold” at the beginning.</p>
<p>You can call <code>mix aoc.run -b</code> to execute an actual benchmark of the both parts. <code>mix aoc.run -d 8 -b</code> for your day 8.</p>
<p>Edit: on day 8 I got this:</p>
<pre><code class="lang-plaintext">Solution for 2024 day 8
part_one: 228 in 6.97ms      &lt;---- part 1 slower
part_two: 766 in 962µs
Benchmarking part_one ...
Benchmarking part_two ...
Calculating statistics...    r-----part 1 faster
Formatting results...        |
                             v
Name               ips        average  deviation         median         99th %
part_one        1.74 K      574.44 μs    ±13.41%      555.32 μs      821.29 μs &lt;---- faster
part_two        1.24 K      803.35 μs     ±8.98%      793.15 μs     1049.71 μs

Comparison:
part_one        1.74 K
part_two        1.24 K - 1.40x slower +228.91 μs
</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="349549" 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-2024-day-10/67999/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-349549" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349549"
                     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 #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/67999/load_more?page=3">Load more posts (4 remaining)</a>
</div></template></turbo-stream>