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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>My solution for day 2:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule AdventOfCode.DayTwo do
  def part_one(input) do
    input
    |&gt; parse_input()
    |&gt; Enum.count(&amp;safe?/1)
  end

  def part_two(input) do
    input
    |&gt; parse_input()
    |&gt; Enum.count(&amp;dampener_analysis/1)
  end

  defp parse_input(input) do
    input
    |&gt; String.split("\n")
    |&gt; Enum.map(fn line -&gt;
      line
      |&gt; String.trim()
      |&gt; String.split()
      |&gt; Enum.map(&amp;String.to_integer/1)
    end)
  end

  defp safe?([l1, l2 | _] = report) do
    trend = if l1 &lt; l2, do: :asc, else: :desc
    safe?(report, trend)
  end

  defp safe?([l1, l2 | _], :asc)
       when l1 &gt; l2,
       do: false

  defp safe?([l1, l2 | _], :desc)
       when l1 &lt; l2,
       do: false

  defp safe?([l1, l2 | _], _)
       when abs(l1 - l2) not in 1..3,
       do: false

  defp safe?([l1, l2], trend) do
    match_trend? =
      if trend == :asc,
        do: l1 &lt; l2,
        else: l1 &gt; l2

    match_trend? and abs(l1 - l2) in 1..3
  end

  defp safe?([_l1, l2 | rest], trend),
    do: safe?([l2 | rest], trend)

  defp dampener_analysis(report) do
    case safe?(report) do
      true -&gt;
        true

      _ -&gt;
        report
        |&gt; Enum.with_index()
        |&gt; Enum.map(fn {_, idx} -&gt;
          safe?(List.delete_at(report, idx))
        end)
        |&gt; Enum.any?()
    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="348164" 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-2/67804/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-348164" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="348164"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #21"></div>
  </section>
</div>
    <div class="postbit" id="348165" data-post-id="348165">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="BartOtten" data-post="21" data-topic="67804">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bartotten/48/25440_2.png" class="avatar"> BartOtten:</div>
<blockquote>
<p><code>        # politician mode: enabled</code></p>
</blockquote>
</aside>
<p><img src="https://forum.elixirforum.com/uploads/default/original/2X/6/6c3193d1dd46244da3c8c6f719c9f5e2abdd5ae8.gif?v=15" title=":003:" class="emoji emoji-custom only-emoji" alt=":003:" loading="lazy" width="20" height="20"></p>
<p>Reminds me of one of George Carlin’s tidbits for when politicians are deflecting blame:</p>
<blockquote>
<p>When the heat builds up, they say: “The whole thing was taken out of context”. Why is it always the whole thing? Apparently, it never happens that only a part of the thing can get taken out of context.</p>
</blockquote> 
	            </div>

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

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #22"></div>
  </section>
</div>
    <div class="postbit" id="348178" data-post-id="348178">
  <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>Long time lurker, using the advent as an excuse to say hi. =]</p>
<p>Here are my solutions for today.</p>
<p>Part 1:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule SafeReports do
  @comparators %{
    gt: "&gt;",
    lt: "&lt;"
  }

  def count([_h], _safe?, _comparator), do: 1

  def count([a | [b | _t] = tail], safe?, comparator) do
    if safe? and apply(Kernel, :"#{@comparators[comparator]}", [a, b]) and abs(a - b) &lt; 4 do
      count(tail, true, comparator)
    else
      0
    end
  end

  def solve() do
    File.stream!("02/input.txt")
    |&gt; Enum.reduce(
      0,
      fn line, safe_report_count -&gt;
        safe_report_count +
          (line
           |&gt; String.trim()
           |&gt; String.split(" ")
           |&gt; Enum.map(&amp;String.to_integer/1)
           |&gt; (fn
                 [a | [b | _t]] = report -&gt;
                   cond do
                     a &lt; b -&gt;
                       :lt

                     a &gt; b -&gt;
                       :gt

                     true -&gt;
                       :eq
                   end
                   |&gt; case do
                     :eq -&gt; 0
                     comparator -&gt; count(report, true, comparator)
                   end
               end).())
      end
    )
    |&gt; IO.puts()
  end
end

SafeReports.solve()
</code></pre>
<p>Part 2:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule SafeReports do
  @comparators %{
    gt: "&gt;",
    lt: "&lt;"
  }

  defp do_count([_h], _safe?, _comparator), do: 1

  defp do_count([a | [b | _t] = tail], safe?, comparator) do
    if safe? and apply(Kernel, :"#{@comparators[comparator]}", [a, b]) and abs(a - b) &lt; 4 do
      do_count(tail, true, comparator)
    else
      0
    end
  end

  defp count([a | [b | _t]] = report) do
    cond do
      a &lt; b -&gt;
        :lt

      a &gt; b -&gt;
        :gt

      true -&gt;
        :eq
    end
    |&gt; case do
      :eq -&gt; 0
      comparator -&gt; do_count(report, true, comparator)
    end
  end

  defp count_if_safe(report) do
    Stream.unfold(
      {0, report},
      fn {index, report} = previous_state -&gt;
        if index &gt;= (report |&gt; Enum.count()) do
          nil
        else
          {previous_state, {index + 1, report}}
        end
      end
    )
    |&gt; Enum.reduce_while(
      0,
      fn {index, report}, _ -&gt;
        case count(report) do
          0 -&gt;
            case count(report |&gt; List.delete_at(index)) do
              0 -&gt; {:cont, 0}
              1 -&gt; {:halt, 1}
            end
          1 -&gt; {:halt, 1}
        end
      end
    )
  end

  def solve() do
    File.stream!("02/input.txt")
    |&gt; Enum.reduce(
      0,
      fn line, safe_report_count -&gt;
        safe_report_count +
          (line
           |&gt; String.trim()
           |&gt; String.split(" ")
           |&gt; Enum.map(&amp;String.to_integer/1)
           |&gt; count_if_safe())
      end
    )
    |&gt; IO.puts()
  end
end

SafeReports.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="348178" 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-2/67804/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-348178" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="348178"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #23"></div>
  </section>
</div>
    <div class="postbit" id="348180" data-post-id="348180">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<pre data-code-wrap="elixir"><code class="lang-elixir">#!/usr/bin/env elixir

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

defmodule Day2 do
  def run(test_file) do
    list = extract_list(test_file)
    IO.puts("Safe Reports: #{safe_reports(list)}")
    IO.puts("Dampened Safe Reports: #{safe_reports_dampened(list)}")
  end

  def safe_reports_dampened(reports_list) do
    Enum.reduce(reports_list, 0, fn list, safe_count -&gt;
      if safe_report?(list) or can_become_safe_by_removing_one?(list),
        do: safe_count + 1,
        else: safe_count
    end)
  end

  def safe_reports(reports_list) do
    Enum.reduce(reports_list, 0, fn list, safe_count -&gt;
      if safe_report?(list),
        do: safe_count + 1,
        else: safe_count
    end)
  end

  defp safe_report?([first, second | _])
       when abs(first - second) &lt; 1 or abs(first - second) &gt; 3,
       do: false

  defp safe_report?([first, second | rest]) do
    direction = if first &gt; second, do: :decreasing, else: :increasing

    Enum.reduce_while(rest, {second, direction}, fn current, {prev, dir} -&gt;
      diff = abs(prev - current)

      cond do
        diff &lt; 1 or diff &gt; 3 -&gt;
          {:halt, :unsafe}

        dir == :increasing and prev &lt; current -&gt;
          {:cont, {current, dir}}

        dir == :decreasing and prev &gt; current -&gt;
          {:cont, {current, dir}}

        true -&gt;
          {:halt, :unsafe}
      end
    end) != :unsafe
  end

  defp can_become_safe_by_removing_one?(list) do
    Enum.any?(Enum.with_index(list), fn {_elem, index} -&gt;
      modified_list = List.delete_at(list, index)
      safe_report?(modified_list)
    end)
  end

  def extract_list(test_file) do
    File.stream!(test_file)
    |&gt; Stream.map(&amp;String.split/1)
    |&gt; Stream.map(fn line -&gt;
      Enum.map(line, &amp;String.to_integer/1)
    end)
    |&gt; Enum.to_list()
  end
end

defmodule Main do
  def main do
    {opts, _, _} = OptionParser.parse(System.argv(), switches: [file: :string])

    case opts do
      [file: test_file] -&gt; Day2.run(test_file)
      _ -&gt; IO.puts("Usage: ./day2.exs --file path/to/test_file.txt")
    end
  end
end

Main.main()
</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="348180" 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-2/67804/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-348180" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="348180"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #24"></div>
  </section>
</div>
    <div class="postbit" id="348384" data-post-id="348384">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I tried something similar that ended up not working. My idea was to find how many inflection points there were in the series. If there were only two direction changes and the length of the middle segment was only one item you just need to know if the item before and the item after satisfy the distance rules.<br>
I had something like</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">list 
|&gt; Enum.zip(tl(list)) 
|&gt; Enum.chunk_by(fn {a,b} -&gt; a - b &gt; 0 end)
</code></pre>
<p>If you have one chunk the list is sorted. If you have two chunks and the second one has a single item dropping the last item in the list would make it sorted. If you have three chunks and the middle chunk has a single pair, dropping the second item in that pair would make the list sorted.</p>
<p>I just couldn’t figure out how to include the max distance criteria.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="348384" 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-2/67804/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-348384" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="348384"
                     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 #25"></div>
  </section>
</div>
    <div class="postbit" id="348393" data-post-id="348393">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Okay a little late to this one. My part 1 halts as soon as we see an error.</p>
<p>Part two is a little more complex but it does not use <code>List.delete_at</code> or anything. It stops as soon as there are more errors than is legal to correct. To satisfy the edge cases you have to attempt each starting sequence if any fail before you can rule the report unsafe.<br>
Could probably make it shorter. But you definitely don’t have to try deleting each element in the list in turn you can be a bit more surgical so I think we avoid the combinatorial explosion.</p>
<h3><a name="p-348393-part-1-1" class="anchor" href="#p-348393-part-1-1" aria-label="Heading link" rel="nofollow"></a>Part 1</h3>
<pre data-code-wrap="elixir"><code class="lang-elixir">  def day_2_1() do
    "./day_2_1_input.txt"
    |&gt; File.read!()
    |&gt; String.split(@new_line, trim: true)
    |&gt; Enum.reduce(0, fn line, count -&gt;
      [one, two | rest] = line |&gt; String.split(" ")
      one = String.to_integer(one)
      two = String.to_integer(two)
      diff = abs(one - two)

      if diff &gt; 0 &amp;&amp; diff &lt; 4 do
        sum_safe_reports([two | rest], one &lt; two, count)
      else
        count
      end
    end)
  end

  defp sum_safe_reports([_final], _, count), do: count + 1

  defp sum_safe_reports([current, next | rest], incrementing?, count) do
    next = String.to_integer(next)

    diff = if incrementing?, do: next - current, else: current - next

    if diff &gt; 0 &amp;&amp; diff &lt; 4 do
      sum_safe_reports([next | rest], incrementing?, count)
    else
      count
    end
  end
</code></pre>
<h3><a name="p-348393-part-2-2" class="anchor" href="#p-348393-part-2-2" aria-label="Heading link" rel="nofollow"></a>Part 2</h3>
<pre data-code-wrap="elixir"><code class="lang-elixir">  def day_2_2() do
    "./day_2_1_input.txt"
    |&gt; File.read!()
    |&gt; String.split(@new_line, trim: true)
    |&gt; Enum.reduce(0, fn line, count -&gt;
      [one, two, three | rest] =
        line |&gt; String.split(" ") |&gt; Enum.map(&amp;String.to_integer/1)

      possible_starting_combos = [
        {one, two, [two, three | rest], 0},
        {one, three, [three | rest], 1},
        {two, three, [three | rest], 1}
      ]

      start_with_pair(possible_starting_combos, count)
    end)
  end

  defp start_with_pair([], count), do: count

  defp start_with_pair([{left, right, rest, errors} | next_iteration], count) do
    new_count =
      if is_safe?(left, right, left &lt; right) do
        sum_safe_reports(rest, left &lt; right, errors, count)
      else
        count
      end

    if count == new_count do
      start_with_pair(next_iteration, count)
    else
      new_count
    end
  end

  defp is_safe?(first, next, incrementing?) do
    diff = if incrementing?, do: next - first, else: first - next
    diff &gt; 0 &amp;&amp; diff &lt; 4
  end

  defp sum_safe_reports([_final], _, _, count), do: count + 1

  defp sum_safe_reports([penultimate, final], incrementing?, errors, count) do
    # If we have 0 errors then we can always fix when there are 2 numbers left.
    if errors &lt; 1 || is_safe?(penultimate, final, incrementing?) do
      count + 1
    else
      count
    end
  end

  defp sum_safe_reports([one, two, three | rest], incrementing?, errors, count) do
    if is_safe?(one, two, incrementing?) do
      sum_safe_reports([two, three | rest], incrementing?, errors, count)
    else
      errors = errors + 1

      if is_safe?(one, three, incrementing?) &amp;&amp; errors &lt; 2 do
        sum_safe_reports([three | rest], incrementing?, errors, count)
      else
        count
      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="348393" 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-2/67804/27">Post #26</a>
	                </div>
	            </div>
              <div id="likers-container-348393" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="348393"
                     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 #26"></div>
  </section>
</div>
    <div class="postbit" id="353378" data-post-id="353378">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Life sadly kept getting in the way but ultimately:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Day02 do
  @moduledoc ~S"""
  A solution to https://adventofcode.com/2024/day/2.
  """

  @type level :: pos_integer()
  @type distance :: integer()
  @type report :: [level()]

  @spec all_variants_with_one_element_removed(report()) :: [report()]
  def all_variants_with_one_element_removed(list) do
    for i &lt;- 0..(length(list) - 1), do: list |&gt; List.delete_at(i)
  end

  @spec sign(integer()) :: :zero | :minus | :plus
  def sign(0), do: :zero
  def sign(i) when i &gt; 0, do: :plus
  def sign(i) when i &lt; 0, do: :minus

  @spec distances(report()) :: [distance()]
  def distances([first | rest]) do
    rest
    |&gt; Enum.reduce({first, []}, fn current_level, {previous_level, distances} -&gt;
      {current_level, [current_level - previous_level | distances]}
    end)
    |&gt; then(fn {_last_level, distances} -&gt; Enum.reverse(distances) end)
  end

  @spec same_signs?([distance()]) :: boolean()
  def same_signs?(list) do
    list
    |&gt; Enum.map(&amp;sign/1)
    |&gt; Enum.uniq()
    |&gt; length()
    |&gt; Kernel.==(1)
  end

  @spec safe?(report()) :: boolean()
  def safe?(report) do
    distances = distances(report)
    monotonical? = same_signs?(distances)

    safely_advancing? =
      distances |&gt; Enum.map(&amp;abs/1) |&gt; Enum.all?(fn distance -&gt; distance &lt;= 3 end)

    monotonical? and safely_advancing?
  end

  @spec safe_with_a_dampener?(report()) :: boolean()
  def safe_with_a_dampener?(report) do
    safe?(report) or
      report |&gt; all_variants_with_one_element_removed() |&gt; Enum.any?(&amp;safe?/1)
  end

  @doc ~S"""
  iex&gt; Day02.part_1("7 6 4 2 1\n1 2 7 8 9\n9 7 6 2 1\n1 3 2 4 5\n8 6 4 4 1\n1 3 6 7 9\n")
  nil
  """
  @spec part_1(String.t()) :: non_neg_integer()
  def part_1(input \\ Aoc.input(2)) do
    input
    |&gt; Aoc.parse_lines_of_integers()
    |&gt; Enum.count(&amp;safe?/1)
  end

  @spec part_2(String.t()) :: non_neg_integer()
  def part_2(input \\ Aoc.input(2)) do
    input
    |&gt; Aoc.parse_lines_of_integers()
    |&gt; Enum.count(&amp;safe_with_a_dampener?/1)
  end
end
</code></pre>
<p>Did my best to make it readable and intuitive, even benchmarked three competing implementation I had ideas about, and only posted the one that won.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="353378" data-batch-url="/posts/batch_likers">
                        3
                      </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-2/67804/28">Post #27</a>
	                </div>
	            </div>
              <div id="likers-container-353378" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="353378"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>