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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="brownerd" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/brownerd/120/27931_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  brownerd
                  </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 Ben.Day01 do
  @moduledoc ~S"""
  Day 01 - Secret Entrance
  """

  @doc ~S"""
  part1/1 takes a string input containing "a sequence of rotation" needed to open a safe to get the password to open the North Pole Base.
  However, our security training tells us that we just need to count the amount of times that the dial on the safe is left pointing at 0.
  Thus, this function returns the amount of times the dial is left pointing at 0.

  ### Example data
  L68
  L30
  R48
  L5
  R60
  L55
  L1
  L99
  R14
  L8

  ### Example usage
  Input must be a path to a data file in the priv directory.

    iex&gt; part1("priv/data/ben/day_01_example_data.txt")
    3

    iex&gt; part1("hello")
    ** (ArgumentError) input must be a path to a file in the priv directory
  """

  @spec part1(String.t()) :: non_neg_integer
  def part1("priv/" &lt;&gt; _rest_of_path = path_to_data) do
    path_to_data
    |&gt; stream_input()
    |&gt; Enum.reduce({50, 0}, &amp;count_zero_positions/2)
    |&gt; elem(1)
  end

  def part1(_incorrect_input),
    do: raise(ArgumentError, "input must be a path to a file in the priv directory")

  defp count_zero_positions(
         &lt;&lt;direction&gt;&gt; &lt;&gt; increment_string = _instruction,
         {current_position, total_times_pointing_at_zero} = _accumulator
       ) do
    {increments, _} = Integer.parse(increment_string)

    new_position =
      case &lt;&lt;direction&gt;&gt; do
        "L" -&gt; rem(current_position - increments + 100, 100)
        "R" -&gt; rem(current_position + increments, 100)
      end

    total_times_pointing_at_zero =
      if new_position == 0,
        do: 1 + total_times_pointing_at_zero,
        else: total_times_pointing_at_zero

    {new_position, total_times_pointing_at_zero}
  end

  # ------------------------------------------------------------------------------

  @doc ~S"""
  Now we need to count the total amount of times the dial points at 0 when executiong each instruction to get the password to the North Pole Base.

    iex&gt; part2("priv/data/ben/day_01_example_data.txt")
    6

    iex&gt; part2("hello")
    ** (ArgumentError) input must be a path to a file in the priv directory

  """
  def part2("priv/" &lt;&gt; _rest_of_path = path_to_data) do
    path_to_data
    |&gt; stream_input()
    |&gt; Enum.reduce({50, 0}, &amp;count_zero_passes/2)
    |&gt; elem(1)
  end

  def part2(_incorrect_input),
    do: raise(ArgumentError, "input must be a path to a file in the priv directory")

  defp count_zero_passes(
         &lt;&lt;direction&gt;&gt; &lt;&gt; increment_string = _instruction,
         {current_position, total_times_pointing_at_zero} = _accumulator
       ) do
    {increments, _} = Integer.parse(increment_string)
    times_passing_zero = div(increments, 100)
    remaining_increments_to_rotate = rem(increments, 100)

    new_position =
      case &lt;&lt;direction&gt;&gt; do
        "L" -&gt; rem(current_position - remaining_increments_to_rotate + 100, 100)
        "R" -&gt; rem(current_position + remaining_increments_to_rotate, 100)
      end

    additional_times_pointing_at_zero =
      case &lt;&lt;direction&gt;&gt; do
        "L" -&gt;
          if current_position != 0 &amp;&amp; current_position - remaining_increments_to_rotate &lt;= 0,
            do: 1 + times_passing_zero,
            else: times_passing_zero

        "R" -&gt;
          if current_position != 0 &amp;&amp; current_position + remaining_increments_to_rotate &gt;= 100,
            do: 1 + times_passing_zero,
            else: times_passing_zero
      end

    {new_position, total_times_pointing_at_zero + additional_times_pointing_at_zero}
  end

  # ------------------------------------------------------------------------------

  defp stream_input(input) do
    File.stream!(input) |&gt; Stream.map(&amp;String.trim/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="379143" 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-2025-day-1/73496/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-379143" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="379143"
                     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="379153" data-post-id="379153">
  <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>I wanted to play a little bit with <code>nimble_parsec</code>. I will try to use it for every parsing job. Usually I use regexes but 1) time to change, 2) and get a more powerful parsing technique.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">#!/usr/bin/env elixir

# Advent of Code 2025. Day 1

Mix.install([
  {:nimble_parsec, "~&gt; 1.4.2"},
])

defmodule M do
  import NimbleParsec

  rotation =
    choice([string("L"), string("R")])
    |&gt; integer(min: 1)

  defparsec :rotation, rotation
end

# Part 1
File.stream!("../day01.txt")
|&gt; Stream.map(fn line -&gt; {:ok, [dir, qty], "\n", %{}, _, _} = M.rotation(line) ; {dir, qty} end)
|&gt; Enum.reduce({50, 0}, fn {dir, qty}, {pos, zeroes} -&gt;
  pos =  Integer.mod(pos + (if dir == "R", do: 1, else: -1) * qty, 100)
  {pos, (if pos == 0, do: zeroes+1, else: zeroes)}
end)
|&gt; tap(fn {_pos, zeroes} -&gt; IO.puts("Day 1. Part 1. Number of zeroes: #{zeroes}") end)

# Part 2
File.stream!("../day01.txt")
|&gt; Stream.map(fn line -&gt; {:ok, [dir, qty], "\n", %{}, _, _} = M.rotation(line) ; {dir, qty} end)
|&gt; Enum.reduce({50, 0}, fn {dir, qty}, {pos, zeroes} -&gt;
  dist_to_zero = if dir == "L", do: pos, else: Integer.mod(100-pos, 100)
  pos =  Integer.mod(pos + (if dir == "R", do: 1, else: -1) * qty, 100)
  n = div(max(0, qty-dist_to_zero), 100) + (if pos != 0 &amp;&amp; qty-dist_to_zero &gt;= 0, do: 1, else: 0)
  {pos, zeroes + n}
end)
|&gt; tap(fn {_pos, zeroes} -&gt; IO.puts("Day 1. Part 2. Number of zeroes: #{zeroes}") 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="379153" data-batch-url="/posts/batch_likers">
                        4
                      </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-1/73496/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-379153" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="379153"
                     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="379158" data-post-id="379158">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mudasobwa" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mudasobwa/120/5298_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mudasobwa
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Cure</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<pre data-code-wrap="elixir"><code class="lang-elixir">  defmodule Day1 do
    @input File.read!("day1_1.input")

    @phase1 false

    if @phase1 do
      defp day1_clicks_r(value) when rem(value, 100) == 0, do: 1
      defp day1_clicks_r(_value), do: 0
      defp day1_clicks_l(current, count), do: day1_clicks_r(current - count)
    else
      defp day1_clicks_r(value), do: div(value, 100)
      defp day1_clicks_l(0, count), do: abs(div(count, 100))
      defp day1_clicks_l(current, count), do: abs(div(current - count - 100, 100))
    end

    defp parse_safe_turn(&lt;&lt;"L", count::binary&gt;&gt;, {current, clicks}) do
      count = String.to_integer(count)
      {rem(10_000 + current - count, 100), clicks + day1_clicks_l(current, count)}
    end

    defp parse_safe_turn(&lt;&lt;"R", count::binary&gt;&gt;, {current, clicks}) do
      count = String.to_integer(count)
      {rem(current + count, 100), clicks + day1_clicks_r(current + count)}
    end

    def parse_input(input \\ @input, start \\ 50) do
      ~r/\s+/
      |&gt; Regex.split(input, trim: true)
      |&gt; Enum.reduce({start, 0}, &amp;parse_safe_turn/2)
    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="379158" 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-2025-day-1/73496/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-379158" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="379158"
                     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="379187" data-post-id="379187">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Late to the party and expected part 2 to trow in some balls, but could easily adapt (add <code>mode</code> to state, add wildguard <code>check_hit</code> clause)</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Aoc2025.Solutions.Y25.Day01 do
  alias AoC.Input

  @state %{cur: 50, hits: 0, mode: nil}
  @min 0
  @max 99

  def parse(input, _part) do
    Input.read!(input) |&gt; String.trim() |&gt; String.split("\n")
  end

  def part_one(problem), do: run(problem, :p1)
  def part_two(problem), do: run(problem, :p2)

  def run(problem, mode) do
    state =
      Enum.reduce(problem, %{@state | mode: mode}, fn line, acc -&gt;
        {direction, amount} = parse_ln(line)
        goto(acc, direction, amount)
      end)

    state.hits
  end

  defp parse_ln("L" &lt;&gt; amount), do: {-1, String.to_integer(amount)}
  defp parse_ln("R" &lt;&gt; amount), do: {1, String.to_integer(amount)}

  defp turn(%{cur: @min} = state, -1), do: %{state | cur: @max}
  defp turn(%{cur: @max} = state, +1), do: %{state | cur: @min}
  defp turn(state, direction), do: %{state | cur: state.cur + direction}

  defp check_hit(%{cur: 0, mode: :p1} = state, 0), do: %{state | hits: state.hits + 1}
  defp check_hit(%{cur: 0, mode: :p2} = state, _), do: %{state | hits: state.hits + 1}
  defp check_hit(state, _), do: state

  defp goto(state, _, 0),
    do: state

  defp goto(state, dir, amount),
    do: state |&gt; turn(dir) |&gt; check_hit(amount - 1) |&gt; goto(dir, amount - 1)
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="379187" 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-2025-day-1/73496/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-379187" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="379187"
                     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="379191" data-post-id="379191">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mudasobwa" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mudasobwa/120/5298_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mudasobwa
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Cure</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><img src="https://forum.elixirforum.com/images/emoji/apple/heart.png?v=15" title=":heart:" class="emoji" alt=":heart:" loading="lazy" width="20" height="20"> <code>goto</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="379191" 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-2025-day-1/73496/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-379191" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="379191"
                     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="379221" data-post-id="379221">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>A little bit late. Also a brute force solution</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule AdventOfCode.Solution.Year2025.Day01 do

  def dial(input, start, mult, counter_func) do

    input

    |&gt; String.split("\\n", trim: true)

    |&gt; Enum.map(fn

"L" &lt;&gt; rest -&gt; -1 \* String.to_integer(rest)

"R" &lt;&gt; rest -&gt; String.to_integer(rest)

end)

    |&gt; Enum.reduce(

      {start, 0},

fn delta, {position, score} -&gt;

        {next_position(position, delta, mult), score + counter_func.(position, delta, mult)}

end

    )

    |&gt; elem(1)

end



defp remp(n, p), do: Integer.mod(n, p)

def next_position(current, delta, mult), do: remp(current + delta, mult)



\# Brute force, but simple

def count_hits(start, delta, mult) do

    step = if delta &lt; 0, do: -1, else: 1

    Enum.count((start + step)..(start + delta)//step, fn i -&gt; remp(i, mult) == 0 end)

end



def stop_at_zero(start, delta, mult) do

  if next_position(start, delta, mult) == 0, do: 1, else: 0

end



def part1(input), do: dial(input, 50, 100, &amp;stop_at_zero/3)

def part2(input), do: dial(input, 50, 100, &amp;count_hits/3)

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="379221" 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-2025-day-1/73496/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-379221" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="379221"
                     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="379222" data-post-id="379222">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Another brute force solution (just discovering the forum)</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule AdventOfCode.Solution.Year2025.Day01 do
  def dial(input, start, mult, counter_func) do
    input
    |&gt; String.split("\n", trim: true)
    |&gt; Enum.map(fn
      "L" &lt;&gt; rest -&gt; -1 * String.to_integer(rest)
      "R" &lt;&gt; rest -&gt; String.to_integer(rest)
    end)
    |&gt; Enum.reduce(
      {start, 0},
      fn delta, {position, score} -&gt;
        {next_position(position, delta, mult), score + counter_func.(position, delta, mult)}
      end
    )
    |&gt; elem(1)
  end

  defp remp(n, p), do: Integer.mod(n, p)
  def next_position(current, delta, mult), do: remp(current + delta, mult)

  # Brute force, but simple
  def count_hits(start, delta, mult) do
    step = if delta &lt; 0, do: -1, else: 1
    Enum.count((start + step)..(start + delta)//step, fn i -&gt; remp(i, mult) == 0 end)
  end

  def stop_at_zero(start, delta, mult) do
    if next_position(start, delta, mult) == 0, do: 1, else: 0
  end

  def part1(input), do: dial(input, 50, 100, &amp;stop_at_zero/3)
  def part2(input), do: dial(input, 50, 100, &amp;count_hits/3)
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="379222" 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-2025-day-1/73496/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-379222" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="379222"
                     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="379245" data-post-id="379245">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="vkryukov" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/vkryukov/120/39604_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  vkryukov
                  </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 Y2025.Day01 do
  def parse(s), do: String.split(s, "\n") |&gt; do_parse()
  def do_parse(l) when is_list(l), do: Enum.map(l, &amp;do_parse/1)
  def do_parse("L" &lt;&gt; num), do: -String.to_integer(num)
  def do_parse("R" &lt;&gt; num), do: String.to_integer(num)

  def part1(s) do
    s
    |&gt; parse()
    |&gt; cum_sum(50)
    |&gt; Enum.count(&amp;(&amp;1 == 0))
  end

  def cum_sum(list, start) do
    list
    |&gt; Enum.reduce([start], fn x, [head | _rest] = list -&gt; [Integer.mod(x + head, 100) | list] end)
  end

  def part2(s) do
    parse(s)
    |&gt; count_rotations(50)
  end

  def count_rotations(list, start) do
    list
    |&gt; Enum.reduce(
      {0, start},
      fn x, {count, cur} -&gt;
        cond do
          x &gt; 0 &amp;&amp; cur + x &lt; 100 -&gt;
            {count, cur + x}

          x &lt; 0 &amp;&amp; cur + x &gt; 0 -&gt;
            {count, cur + x}

          true -&gt;
            new_head = Integer.mod(cur + x, 100)
            inc = div(abs(cur + x), 100) + if x &lt; 0 &amp;&amp; cur != 0, do: 1, else: 0
            {count + inc, new_head}
        end
      end
    )
    |&gt; elem(0)
  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="379245" 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-1/73496/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-379245" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="379245"
                     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="379253" data-post-id="379253">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I removed part 1 when doing part 2, so this is only part 1</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Day1 do
  def file, do: Parser.read_file(1)
  def test, do: Parser.read_file("test")

  def parse(input) do
    input
    |&gt; Enum.reject(&amp;is_nil/1)
    |&gt; Enum.map(&amp;get_number/1)
  end

  def get_number("R" &lt;&gt; nb), do: {"R", String.to_integer(nb)}
  def get_number("L" &lt;&gt; nb), do: {"L", String.to_integer(nb)}
  def get_number(a), do: IO.inspect(a)

  def solve(input \\ file()) do
    input
    |&gt; parse()
    |&gt; Enum.reduce({50, 0}, fn instructions, {current_pos, counter} -&gt;
      calculate_next(current_pos, instructions, counter)
    end)
  end

  # because if you start a 0, the go_back_to_100 will consider you need to add one to the counter
  # but you shouldn't because you were already at 0
  def calculate_next(0, {"L", number}, counter) do
    go_back_to_100(0 - number, counter - 1)
  end

  def calculate_next(current_nb, {"L", number}, counter) do
    go_back_to_100(current_nb - number, counter)
  end

  def calculate_next(current_nb, {"R", number}, counter) do
    go_back_to_100(current_nb + number, counter)
  end

  def go_back_to_100(100, counter), do: {0, counter + 1}
  def go_back_to_100(0, counter), do: {0, counter + 1}
  def go_back_to_100(nb, counter) when nb &gt; 99, do: go_back_to_100(nb - 100, counter + 1)
  def go_back_to_100(nb, counter) when nb &lt; 0, do: go_back_to_100(100 + nb, counter + 1)
  def go_back_to_100(nb, counter), do: {nb, counter}
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="379253" 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-1/73496/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-379253" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="379253"
                     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="379559" data-post-id="379559">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m starting late this year, as I was waiting for an offline event I organised today to “work on the first few days”. It turns out I didn’t even finish day 1, thanks to part 2 <img src="https://forum.elixirforum.com/images/emoji/apple/melting_face.png?v=15" title=":melting_face:" class="emoji" alt=":melting_face:" loading="lazy" width="20" height="20"></p>
<p>I also spent far too long thinking about loops and stuff, before I decided to just brute force every click, which it managed in 3ms.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  def part2(rotations) do
    Enum.reduce(rotations, {_pos = 50, _password = 0}, fn rotation, {pos, password} -&gt;
      new_pos = pos + rotation
      step = if pos &lt; new_pos, do: 1, else: -1

      password =
        for click &lt;- (pos + step)..new_pos//step, reduce: password do
          password -&gt; if Integer.mod(click, 100) == 0, do: password + 1, else: password
        end

      {Integer.mod(new_pos, 100), password}
    end)
    |&gt; elem(1)
  end
</code></pre>
<p><a href="https://git.adamu.jp/adam/AdventOfCode/src/branch/main/2025/day1.exs" class="onebox" target="_blank" rel="noopener nofollow ugc">https://git.adamu.jp/adam/AdventOfCode/src/branch/main/2025/day1.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="379559" 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-1/73496/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-379559" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="379559"
                     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/73496/load_more?page=3">Load more posts (3 remaining)</a>
</div></template></turbo-stream>