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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>My solution. I solved Part 2 manually by printing each second’s grid, too. For part 1 I was also inspired by the solutions already posted in this thread.</p>
<p><a href="https://github.com/Flo0807/adventofcode/blob/main/2024/14.livemd" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/Flo0807/adventofcode/blob/main/2024/14.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="349760" 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-14/68091/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-349760" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349760"
                     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="349769" data-post-id="349769">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I did solve part 1 with simple modulo operations like most of us.</p>
<p>Concerning part 2, I did render the “animation” (at x4 speed) in my console.<br>
2 patterns appeared for the first time in the first 100 frames and then reappeared regularly respectively every 101 and 103 frames.<br>
With the guess that the Christmas tree appears when both patterns are applied to the same frame, the chinese remainder theorem gave me the solution.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="349769" data-batch-url="/posts/batch_likers">
                        2
                      </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-14/68091/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-349769" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349769"
                     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="349784" data-post-id="349784">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Oh my, I am not proud of my Part 2. My <code>is_a_christmas_tree?/1</code> function is the absolute worst. It took 272 seconds to get to the answer.</p>
<p><a href="https://github.com/rvnash/aoc2024/blob/main/lib/d14.ex" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/rvnash/aoc2024/blob/main/lib/d14.ex</a></p>
<p>But, lots of decorating to do today, moving on.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="349784" 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-14/68091/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-349784" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349784"
                     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="349787" data-post-id="349787">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a href="https://topaz.github.io/paste/#XQAAAQAqCwAAAAAAAAAyGUkFUehZxfOWmzTWjQS4wLVJDMV53NKyIELd2ujo3yL9PIHPcb9osN6TTFuM2R0yt/qoPHxTRQE5Gr68bUOjVK3m69HHxS0+beeocRP+jGKRKx17f/GRtQpnsy2xzbLqcW1cADDeFAb5k0i2Msf6cbLh417Kck0PnkI6oWL+9kGHrL8PaWfiOjTStf7+0uAPNvzEhlXJibNN7AOMboFuumofALrSsvATILCL+XJPFvCPaNEXvsuYOpO+vCxBXhGqU3srMeWveE7FJjxzYCqSW+k1tb5D7T/VPKUhWNUz0DRzxwL7DSlmW5Cxw3T1nF2V31S/vSVtA1BPhnxgEuA30NJht6p9CG6bN/SmUVpNJh3fcmLxlPz8pgowuv3zVhAjaW7NRoYF8KmKLeH5q6bxPcw3+uFuzBzUlZ666oEt7Iehk2uzQpgRmw8yGRN8kLnVglsbLpbmCDYLgGtUmLPzGQPJP8Im/FhW7XuA+OBJYU60xH5ie4kVnfeTbe8lMjALlcGgenNfgZnMjmXK29Re6szS/AiOgpsa0OlICUjeOoXFeBdUJ8n0cJ2cW3gLhKyWDkueQd3g6frtMwOgiZ2UgamzdWtiJ9UgLyrYxFURRf+zxxM8JEVQ4l1+tx3it8Sh6sQEbVIWO2+XKbJHznBOX1dRLq9Crc1YOqRpUFwNUdueA2uVACn73KxG0CfhjTOAulpvZbEurNc1Y+JLw3gPhO3qNPO57PhZAZ/kztNoOTPS2az3Tna/acdCgF28YUC/C0FKCgMwV4TwjVJi5QzykI6qJ3B0vQJBaM+2dWGTewhBKOAIBBWh/Mfp4WhbbYSQjtJuV5EJYX+a70WbyufmQxMfJdBzdhMUkNV53bQWxs7R9QSz49ZYVdSGX/M1WT+qxgtT+U7GxX+6OYpCv2j9d8407tG969ujPCbiQ4Pe8/oLZrp3T7qnmCratlnQYyST9pFXPLw/gCHYnUeryxcESUbNdeifcN2stOqmdhenfxcA4P3ey1G0UaZlPkKLOvRKRgOykXPhgd/YvQMUZTyLnea5Tqr3hPsIo9WmTuJ/Q2RtXYe8+sM0xFIK+3j2pUm5wgaznH76IodZNe59P/61u4m/GC9l42yElQzces4hJSlWN2HMdijr245edsgpefWcDMnRENIWkuIbylCYCDH3s/IEyxtNcL60ZhAn2FQp14X2pCRQz+eMddBs6yQoeLszdHHbBg3ioQq/qJ5M0d5CGgqFFqOYQ5H8JQ6L9PuacWoNFxOZDyIezrjvHTi0Pdfd8jYqwrz5sQreFpF4xckkbcbQShxiXngVzpjStLbYDW3Yn/39g4FpNjH/5MBnWA==" rel="noopener nofollow ugc">paste</a></p>
<p>I had an annoying bug with my home made mod function that meant part1 took longer than it should. Nice to learn about Integer.mod. Do you think it would be good to add a note about the existance of Integer.mod to the documentation for rem()?</p>
<p>For part 2 I tried various huristics until I decided to reuse the regions finding function from day 12. That worked fine but was lucky as they could have easily drawn a tree without touching. I was very close to realising I could have looked for seconds where they are in unique positons (although again that is just a heuristic I guess).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="349787" 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-14/68091/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-349787" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349787"
                     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="349802" data-post-id="349802">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Finding minimal variance of positions worked for me in part 2. For each second in range <code>0..(101 * 103)</code> I’ve calculated variance of robots’ positions:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  defp variance(positions) do
    {xs, ys} = Enum.unzip(positions)
    xl = length(xs)
    yl = length(ys)
    xmean = Enum.sum(xs) / xl
    ymean = Enum.sum(ys) / yl
    xvar = Enum.sum(Enum.map(xs, fn x -&gt; (x - xmean) ** 2 end)) / xl
    yvar = Enum.sum(Enum.map(ys, fn y -&gt; (y - ymean) ** 2 end)) / yl
    (xvar + yvar) / 2
  end
</code></pre>
<p>The second with minimal variance was the solution.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="349802" data-batch-url="/posts/batch_likers">
                        5
                      </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-14/68091/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-349802" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349802"
                     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="349806" data-post-id="349806">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Went for a semi, brute force method here. Generated .txt files of the first 200 options, spotted that there was a sequence of when the robots seemed to come together, so then decided to try searching for a block of xxxx in the txt representation of the grid, and I was lucky!</p>
<p>Should really tidy it up to not be converting to a string every time for speed, but it works and I’m short on time today!</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Aoc2024.Solutions.Y24.Day14 do
  alias AoC.Input

  def parse(input, _part) do
    Input.read!(input)
    |&gt; String.split("\n", trim: true)
    |&gt; Enum.map(fn robot -&gt;
      [rob, speed] = String.split(robot, " ", trim: true)
      {get_x_y(rob), get_x_y(speed)}
    end)
  end

  def get_x_y(loc) do
    [x, y] = String.split(loc, ",", trim: true)
    x = String.split(x, "=", trim: true) |&gt; List.last() |&gt; String.to_integer()
    y = String.to_integer(y)
    {x, y}
  end

  def part_one(problem) do
    grid_x = 100
    grid_y = 102
    middle_x = 50
    middle_y = 51

    {a, b, c, d} =
      problem
      |&gt; perform_moves({grid_x, grid_y}, 100, 0)
      # |&gt; Enum.map(&amp;perform_moves(&amp;1, {grid_x, grid_y}, 100, 0))
      |&gt; Enum.reduce({0, 0, 0, 0}, fn robot, acc -&gt;
        acc = find_quadrant(robot, acc, {middle_x, middle_y})
        acc
      end)

    a * b * c * d
  end

  def part_two(problem) do
    grid_x = 100
    grid_y = 102

    problem
    |&gt; perform_moves_pt_2({grid_x, grid_y}, 8000, 0)
  end

  def find_quadrant(
        {{loc_x, loc_y}, _},
        {quad_1, quad_2, quad_3, quad_4} = acc,
        {middle_x, middle_y}
      ) do
    cond do
      loc_x &lt; middle_x &amp;&amp; loc_y &lt; middle_y -&gt;
        {quad_1 + 1, quad_2, quad_3, quad_4}

      loc_x &gt; middle_x &amp;&amp; loc_y &lt; middle_y -&gt;
        {quad_1, quad_2 + 1, quad_3, quad_4}

      loc_x &lt; middle_x &amp;&amp; loc_y &gt; middle_y -&gt;
        {quad_1, quad_2, quad_3 + 1, quad_4}

      loc_x &gt; middle_x &amp;&amp; loc_y &gt; middle_y -&gt;
        {quad_1, quad_2, quad_3, quad_4 + 1}

      true -&gt;
        acc
    end
  end

  def perform_moves(robots, {_grid_x, _grid_y}, count, acc) when acc == count, do: robots

  def perform_moves(robots, {grid_x, grid_y}, count, acc) do
    robots =
      Enum.map(robots, fn robot -&gt;
        perform_move(robot, {grid_x, grid_y})
      end)

    perform_moves(robots, {grid_x, grid_y}, count, acc + 1)
  end

  def perform_moves_pt_2(robots, {_grid_x, _grid_y}, count, acc) when acc == count, do: robots

  @first_1 59
  @diff_1 103
  @tick_1 Enum.map(1..100, fn n -&gt; @first_1 + (n - 1) * @diff_1 end)
  @first_2 82
  @diff_2 101
  @tick_2 Enum.map(1..100, fn n -&gt; @first_2 + (n - 1) * @diff_2 end)
  @ticks @tick_1 ++ @tick_2

  def perform_moves_pt_2(robots, {grid_x, grid_y}, count, acc) do
    robots =
      Enum.map(robots, fn robot -&gt;
        perform_move(robot, {grid_x, grid_y})
      end)

    if acc in @ticks do
      if check_for_tree(robots) do
        acc
      else
        perform_moves_pt_2(robots, {grid_x, grid_y}, count, acc + 1)
      end
    else
      perform_moves_pt_2(robots, {grid_x, grid_y}, count, acc + 1)
    end
  end

  def check_for_tree(robots) do
    grid = for _ &lt;- 0..102, do: for(_ &lt;- 0..100, do: ".")

    Enum.reduce(robots, grid, fn {{x, y}, _}, acc -&gt;
      List.update_at(acc, y, fn row -&gt;
        List.update_at(row, x, fn _ -&gt; "#" end)
      end)
    end)
    |&gt; Enum.join(" ")
    |&gt; String.contains?("##########")
  end

  def print_coordinates_grid(coordinates, acc) do
    grid = for _ &lt;- 0..102, do: for(_ &lt;- 0..100, do: ".")

    updated_grid =
      Enum.reduce(coordinates, grid, fn {{x, y}, _}, acc -&gt;
        List.update_at(acc, y, fn row -&gt;
          List.update_at(row, x, fn _ -&gt; "#" end)
        end)
      end)

    file =
      Enum.reduce(updated_grid, "", fn row, acc -&gt;
        acc &lt;&gt; Enum.join(row, "") &lt;&gt; "\n"
      end)

    File.write!("output_#{acc}.txt", file)
  end

  def perform_move({{x, y}, {speed_x, speed_y}}, {grid_x, grid_y}) do
    updated_x = calulate_next_position(x, speed_x, grid_x)
    updated_y = calulate_next_position(y, speed_y, grid_y)
    {{updated_x, updated_y}, {speed_x, speed_y}}
  end

  def calulate_next_position(current, speed, grid_size) when current + speed &gt; grid_size do
    current - 1 + speed - grid_size
  end

  def calulate_next_position(current, speed, grid_size) when current + speed &lt; 0 do
    grid_size + 1 + current + speed
  end

  def calulate_next_position(current, speed, _grid_size) do
    current + speed
  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="349806" 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-14/68091/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-349806" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349806"
                     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="349807" data-post-id="349807">
  <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>Had to come here to get some idea of what the christmas tree was supposed to look like so I could figure out how to search for it. Once I knew that it was fairly straightforward since I had written function to output a grid layout for debugging for a previous day.</p>
<p>AOC continues to be a great way for me to learn the Elixir standard library. I think I’ve used a new-to-me function every day.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">require Grid

defmodule Aoc2024.Day14 do
  @moduledoc false

  def part1(file, size) do
    seconds = 100
    get_input(file)
    |&gt; Enum.map(&amp;move(&amp;1, seconds, size))
    |&gt; Enum.map(&amp;quadrant(&amp;1, size))
    |&gt; Enum.frequencies()
    |&gt; Map.delete(0)
    |&gt; Map.values()
    |&gt; Enum.product()
  end

  def part2(file, size) do
    robots = get_input(file)
    Enum.reduce_while(1..10_000, robots, fn seconds, robots -&gt;
      output = Enum.map(robots, &amp;move(&amp;1, seconds, size))
      |&gt; Enum.frequencies()
      |&gt; Grid.new(size)
      |&gt; Grid.output(" ")
      if Regex.match?(~r/\d{8}/, output) do
        IO.puts("#{seconds} seconds:")
        IO.puts(output)
        {:halt, seconds}
      else
        {:cont, robots}
      end
    end)
  end

  defp get_input(file) do
    File.read!(file)
    |&gt; String.trim()
    |&gt; String.split("\n", trim: true)
    |&gt; Enum.map(fn line -&gt;
      [px, py, vx, vy] =
        Regex.run(~r/p=(?&lt;px&gt;\d+),(?&lt;py&gt;\d+) v=(?&lt;vx&gt;-?\d+),(?&lt;vy&gt;-?\d+)/, line,
          capture: ["px", "py", "vx", "vy"]
        )
        |&gt; Enum.map(&amp;String.to_integer/1)

      {px, py, vx, vy}
    end)
  end

  defp move(_robot = {px, py, vx, vy}, seconds, _size = {sx, sy}) do
    newx = Integer.mod(px + vx * seconds, sx)
    newy = Integer.mod(py + vy * seconds, sy)
    {newx, newy}
  end

  defp quadrant(_robot_position = {px, py}, _size = {sx, sy}) do
    midx = div(sx, 2)
    midy = div(sy, 2)
    cond do
      px == midx or py == midy -&gt;
        0
      px &lt; midx and py &lt; midy -&gt;
        1
      px &gt; midx and py &lt; midy -&gt;
        2
      px &lt; midx and py &gt; midy -&gt;
        3
      px &gt; midx and py &gt; midy -&gt;
        4
    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="349807" 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-14/68091/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-349807" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349807"
                     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="349836" data-post-id="349836">
  <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><s>For whatever reason, this is correct for the example, but incorrect for the input. I’m confused as to why. My initial implementation looked a lot like <a class="mention" href="/u/adamu" rel="nofollow">@adamu</a>’s. I’ve since refactored it to be nearly identical, but it still doesn’t pass.</s> ← see my reply. This works with a different regex.</p>
<p>I also noticed that the final output for the example has one robot at position <code>9,0</code> instead of <code>10,0</code> where my code calculates it. <img src="https://forum.elixirforum.com/images/emoji/apple/slightly_frowning_face.png?v=15" title=":slightly_frowning_face:" class="emoji" alt=":slightly_frowning_face:" loading="lazy" width="20" height="20"> Maybe a typo in the example output?</p>
<p>Anyone able to point me in the right direction?</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Day14.Part1 do
  @seconds 100
  @width 101
  @height 103
  @center_column div(@width, 2)
  @center_row div(@height, 2)

  defp parse(str) do
    str
    |&gt; String.split("\n", trim: true)
    |&gt; Enum.map(&amp;parse_bot/1)
  end

  defp parse_bot(line) do
    Regex.scan(~r/-?\d,-?\d/, line)
    |&gt; Enum.flat_map(fn [pair] -&gt;
      [
        String.split(pair, ",")
        |&gt; Enum.map(&amp;String.to_integer/1)
        |&gt; List.to_tuple()
      ]
    end)
  end

  defp iterate(bots) do
    bots
    |&gt; Enum.reduce(
      {0,0,0,0},
      fn [{p_x, p_y}, {v_x, v_y}] = _bot, {q1_bots, q2_bots, q3_bots, q4_bots} = bots -&gt;
        delta_x = v_x * @seconds
        delta_y = v_y * @seconds
        final_x = Integer.mod(p_x + delta_x, @width)
        final_y = Integer.mod(p_y + delta_y, @height)

        case {final_x, final_y} do
          {x, y} when x &lt; @center_column and y &lt; @center_row -&gt; {q1_bots + 1, q2_bots, q3_bots, q4_bots}
          {x, y} when x &lt; @center_column and y &gt; @center_row -&gt; {q1_bots, q2_bots + 1, q3_bots, q4_bots}
          {x, y} when x &gt; @center_column and y &lt; @center_row -&gt; {q1_bots, q2_bots, q3_bots + 1, q4_bots}
          {x, y} when x &gt; @center_column and y &gt; @center_row -&gt; {q1_bots, q2_bots, q3_bots, q4_bots + 1}
          _ -&gt; bots
        end
      end
    )
    |&gt; Tuple.product()
  end

  def solve() do
    File.read!("lib/advent_of_code/year/2024/day/14/input.txt")
    |&gt; parse()
    |&gt; dbg()
    |&gt; iterate()
    |&gt; IO.puts()
  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="349836" 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-14/68091/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-349836" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349836"
                     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="349837" data-post-id="349837">
  <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>Woops. Got it.</p>
<p>My regex for parsing was missing <code>+</code> chars after matching each <code>\d</code> <img src="https://forum.elixirforum.com/images/emoji/apple/person_facepalming.png?v=15" title=":person_facepalming:" class="emoji" alt=":person_facepalming:" loading="lazy" width="20" height="20"></p>
<p>Working regex for the above code: <code>~r/-?\d+,-?\d+/</code></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="349837" 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-14/68091/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-349837" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349837"
                     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="349842" data-post-id="349842">
  <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>Read some comments here and on Reddit to get some ideas and eventually tried finding an horizontal line of at least 10 robots. Should have found it by myself. Anyway, it was a cool one.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">#!/usr/bin/env elixir

# AoC 2024. day 14.

to_i = &amp;String.to_integer/1

advance = fn robots, sec -&gt;
  Enum.map(robots, fn robot -&gt;
    %{robot |
      x: Integer.mod(robot.x+sec*robot.vx,101),
      y: Integer.mod(robot.y+sec*robot.vy,103) }
  end)
  # sorting is used in part 2
  |&gt; Enum.sort(fn o1, o2 -&gt; o1.y &lt; o2.y || o1.y == o2.y &amp;&amp; o1.x &lt;= o2.x end)
end

count = fn robots -&gt;
  Enum.reduce(robots, {0,0,0,0}, fn robot, {q1,q2,q3,q4} -&gt;
    cond do
      robot.x &lt; 50 &amp;&amp; robot.y &lt; 51 -&gt; {q1+1,q2,q3,q4}
      robot.x &gt; 50 &amp;&amp; robot.y &lt; 51 -&gt; {q1,q2+1,q3,q4}
      robot.x &lt; 50 &amp;&amp; robot.y &gt; 51 -&gt; {q1,q2,q3+1,q4}
      robot.x &gt; 50 &amp;&amp; robot.y &gt; 51 -&gt; {q1,q2,q3,q4+1}
      true -&gt; {q1,q2,q3,q4}
    end
  end)
end

###########################################################
# Setup

robots = File.stream!("../day14.txt")
  |&gt; Stream.map(fn s -&gt; Regex.run(~r/^p=(\d+),(\d+) v=(-?\d+),(-?\d+)/, s, capture: :all_but_first) end)
  |&gt; Enum.reduce([], fn [x, y, vx, vy], lst -&gt; [%{x: to_i.(x), y: to_i.(y), vx: to_i.(vx), vy: to_i.(vy)} | lst] end)
  # sorting is used in part 2
  |&gt; Enum.sort(fn o1, o2 -&gt; o1.y &lt; o2.y || o1.y == o2.y &amp;&amp; o1.x &lt;= o2.x end)

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

start = System.monotonic_time(:microsecond)
robots
|&gt; advance.(100)
|&gt; count.()
|&gt; then(fn {q1,q2,q3,q4} -&gt; q1*q2*q3*q4 end)
|&gt; IO.inspect(label: "Part 1")
elapsed = System.monotonic_time(:microsecond) - start
IO.puts "Job done in #{elapsed} µs"

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

defmodule M do
  @min_aligned 10
  def horizontal_line(robots), do: horizontal_line(robots, 0, nil)
  defp horizontal_line([], aligned, _prev), do: aligned &gt;= @min_aligned
  defp horizontal_line([r | robots], 0, nil), do: horizontal_line(robots, 0, r)
  defp horizontal_line([r | robots], aligned, prev) do
    cond do
      aligned &gt;= @min_aligned -&gt; true
      r.y == prev.y &amp;&amp; r.x == prev.x+1 -&gt; horizontal_line(robots, aligned+1, r)
      true -&gt; horizontal_line(robots, 0, r)
    end
  end
end

display = fn robots, x0, y0, width, height -&gt;
  robots = Map.new(robots, fn r -&gt; {{r.x,r.y},{r.vx,r.vy}} end)
  for y &lt;- y0..y0+height, x &lt;- x0..x0+width, reduce: y0 do
    prev_y -&gt; if y != prev_y, do: IO.puts("")
      if robots[{x,y}] do
        IO.write "#"
      else
        IO.write "."
      end
      y
  end
  IO.puts ""
end

start = System.monotonic_time(:microsecond)
Stream.iterate({robots, 0}, fn {robots, time} -&gt;
  robots = advance.(robots, 1)
  {robots, time+1}
end)
|&gt; Stream.drop_while(fn {robots, _time} -&gt;
  !M.horizontal_line(robots)
end)
|&gt; Enum.at(0)
|&gt; then(fn {robots, time} -&gt; display.(robots, 0, 0, 101, 103) ; time 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="349842" 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-14/68091/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-349842" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349842"
                     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/68091/load_more?page=3">Load more posts (13 remaining)</a>
</div></template></turbo-stream>