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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I also was provided no overlaps in my part 2 example input, so had nothing to go on to problem solve my initial wrong answer. <img src="https://forum.elixirforum.com/images/emoji/apple/sweat_smile.png?v=15" title=":sweat_smile:" class="emoji" alt=":sweat_smile:" loading="lazy" width="20" height="20"></p>
<details><summary>Preprocessing input</summary>
<p>Source <a href="https://github.com/christhekeele/aoc/blob/main/2023/day/1/input.ex" rel="noopener nofollow ugc">available here</a>.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule AoC.Day.One.Input do
  def parse(input_file \\ System.fetch_env!("INPUT_FILE")) do
    input_file
    |&gt; File.read!()
    |&gt; String.split("\n")
  end
end
</code></pre>
</details>
<h2><a name="p-309591-part-1-1" class="anchor" href="#p-309591-part-1-1" aria-label="Heading link" rel="nofollow"></a>Part 1</h2>
<details><summary>Solution</summary>
<p>Lazy regex string scanning. Source <a href="https://github.com/christhekeele/aoc/blob/main/2023/day/1/part/1.ex" rel="noopener nofollow ugc">available here</a>.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule AoC.Day.One.Part.One do
  def solve(input) do
    input
    |&gt; Enum.map(fn string -&gt;
      digits =
        ~r{\d}
        |&gt; Regex.scan(string)
        |&gt; List.flatten()

      {first, last} = {List.first(digits), List.last(digits)}
      (first &lt;&gt; last) |&gt; String.to_integer()
    end)
    |&gt; Enum.sum()
  end
end
</code></pre>
</details>
<h2><a name="p-309591-part-2-2" class="anchor" href="#p-309591-part-2-2" aria-label="Heading link" rel="nofollow"></a>Part 2</h2>
<details><summary>Solution</summary>
<p>Metaprogramming literal binary matching into function heads with an accumulator. Source <a href="https://github.com/christhekeele/aoc/blob/main/2023/day/1/part/2.ex" rel="noopener nofollow ugc">available here</a>.</p>
<p>I handle overlapping by re-prefixing the matched word, minus the leading letter, to the continue parsing the string character-by-character:</p>
<p><code>String.slice(word, 1..-1) &lt;&gt; rest</code></p>
<p>This is overkill for the english language, where overlaps can only happen on the last letter, so the parser could just skip to the end:</p>
<p><code>String.at(at, -1) &lt;&gt; rest</code></p>
<p>I like to think that my solution is resiliant to spelling changes in the future of the english language, however. We all know it should be spelled <code>"eeight"</code>, right?</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule AoC.Day.One.Part.Two do
  def solve(input) do
    input
    |&gt; Enum.map(fn string -&gt;
      digits = parse(string)
      {first, last} = {List.first(digits), List.last(digits)}
      (first &lt;&gt; last) |&gt; String.to_integer()
    end)
    |&gt; Enum.sum()
  end

  def parse(string) do
    string |&gt; do_parse([]) |&gt; :lists.reverse()
  end

  # 0?
  @digits ~w[1 2 3 4 5 6 7 8 9]

  for digit &lt;- @digits do
    defp do_parse(unquote(digit) &lt;&gt; rest, acc) do
      do_parse(rest, [unquote(digit) | acc])
    end
  end

  # zero?
  @word_digit_lookup %{
    "one" =&gt; "1",
    "two" =&gt; "2",
    "three" =&gt; "3",
    "four" =&gt; "4",
    "five" =&gt; "5",
    "six" =&gt; "6",
    "seven" =&gt; "7",
    "eight" =&gt; "8",
    "nine" =&gt; "9"
  }

  for {word, digit} &lt;- @word_digit_lookup do
    defp do_parse(unquote(word) &lt;&gt; rest, acc) do
      do_parse(unquote(String.slice(word, 1..-1)) &lt;&gt; rest, [unquote(digit) | acc])
    end
  end

  # Abort recursion when out of characters
  defp do_parse("", acc), do: acc
  # Otherwise, start scan from next character
  defp do_parse(&lt;&lt;_char::binary-size(1), rest::binary&gt;&gt;, acc), do: do_parse(rest, acc)
end
</code></pre>
</details> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="309591" 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-2023-day-1/60073/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-309591" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="309591"
                     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="309593" data-post-id="309593">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<pre data-code-wrap="elixir"><code class="lang-elixir">import AOC

aoc 2023, 1 do
  def calibration(input) do
    input
    |&gt; String.split("", trim: true)
    |&gt; Enum.filter(&amp;("0" &lt;= &amp;1 and &amp;1 &lt;= "9"))
    |&gt; then(&amp;String.to_integer("#{hd(&amp;1)}#{List.last(&amp;1)}"))
  end

  def p1(input) do
    input 
    |&gt; String.split("\n", trim: true)
    |&gt; Enum.map(&amp;calibration/1)
    |&gt; Enum.sum()
  end

  def p2(input) do
    %{one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9}
    |&gt; Enum.reduce(input, fn {word, number}, s -&gt; String.replace(s, "#{word}", "#{word}#{number}#{word}", global: true) end)
    |&gt; p1()
  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="309593" 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-2023-day-1/60073/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-309593" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="309593"
                     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="309595" data-post-id="309595">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Elixir noob here. My <strong>beautiful</strong> solution:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def get_sum_of_calibration_values(text) do
    text
    |&gt; String.split("\n", trim: true)
    |&gt; Enum.reduce(0, fn x, acc -&gt; acc + get_calibration_value(x) end)
  end

  def get_calibration_value(line) do
    positions =
      [get1(line)] ++
        [get2(line)] ++
        [get3(line)] ++
        [get4(line)] ++
        [get5(line)] ++
        [get6(line)] ++
        [get7(line)] ++
        [get8(line)] ++
        [get9(line)]

    first =
      positions
      |&gt; Enum.filter(fn x -&gt; x.first &gt;= 0 end)
      |&gt; Enum.min_by(fn x -&gt; x.first end)
      |&gt; Map.get(:number)

    last =
      positions
      |&gt; Enum.filter(fn x -&gt; x.last &gt;= 0 end)
      |&gt; Enum.max_by(fn x -&gt; x.last end)
      |&gt; Map.get(:number)

    first*10 + last

  end

  def get1(line) do
    hits = Regex.scan(~r/(1)|(one)/, line, return: :index)

    case hits do
      [] -&gt;
        %{number: 1, first: -1, last: -1}

      _ -&gt;
        [[{first, _} | _] | _] = hits
        [[{last, _} | _] | _] = Enum.reverse(hits)
        %{number: 1, first: first, last: last}
    end
  end

  def get2(line) do
    hits = Regex.scan(~r/(2)|(two)/, line, return: :index)

    case hits do
      [] -&gt;
        %{number: 2, first: -1, last: -1}

      _ -&gt;
        [[{first, _} | _] | _] = hits
        [[{last, _} | _] | _] = Enum.reverse(hits)
        %{number: 2, first: first, last: last}
    end
  end
</code></pre>
<p>… and so forth</p> 
	            </div>

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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I like this approach. I can’t explain why, but I really wanted to see someone do this without string replacements.</p>
<p><strong>Edit</strong>: I absolutely can explain why, it’s because I didn’t think to use string replacements. I am stubborn and want to see others do it succinctly without them.</p> 
	            </div>

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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Open to suggestions on how to clean this up. I’ve just begun writing Elixir last month, so any insight into idioms/patterns to improve this would be great.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Day1_2023 do
  def solve(input) do
    input
    |&gt; Enum.filter(&amp;(String.length(&amp;1) &gt; 0))
    |&gt; Enum.reduce(
      0,
      fn line, acc -&gt;
        acc + parse_number(line)
      end
    )
  end

  def parse_number(line) do
    left_number = find_first_number(line)
    right_number = find_first_number_from_right(line)
    left_number * 10 + right_number
  end

  def find_first_number(l) do
    1..(l |&gt; String.length())
    |&gt; Enum.reduce_while(
      0,
      fn i, _ -&gt;
        int_at_pos = l |&gt; String.at(i - 1) |&gt; Integer.parse()

        case int_at_pos do
          :error -&gt;
            l
            |&gt; String.slice(0, i)
            |&gt; search_for_written_number()
            |&gt; then(fn res -&gt;
              case res do
                nil -&gt; {:cont, 0}
                n -&gt; {:halt, n}
              end
            end)

          n -&gt;
            {:halt, n |&gt; elem(0)}
        end
      end
    )
  end

  def find_first_number_from_right(l) do
    len = String.length(l)

    1..len
    |&gt; Enum.reduce_while(
      0,
      fn i, _ -&gt;
        cur_char = l |&gt; String.at(len - i)
        int_at_pos = cur_char |&gt; Integer.parse()

        case int_at_pos do
          :error -&gt;
            l
            |&gt; String.slice(len - i, len)
            |&gt; search_for_written_number()
            |&gt; then(fn res -&gt;
              case res do
                nil -&gt; {:cont, 0}
                n -&gt; {:halt, n}
              end
            end)

          {n, _} -&gt;
            {:halt, n}
        end
      end
    )
  end

  def search_for_written_number(line) do
    numbers = [
      "one",
      "two",
      "three",
      "four",
      "five",
      "six",
      "seven",
      "eight",
      "nine"
    ]

    numbers_map = %{
      "one" =&gt; 1,
      "two" =&gt; 2,
      "three" =&gt; 3,
      "four" =&gt; 4,
      "five" =&gt; 5,
      "six" =&gt; 6,
      "seven" =&gt; 7,
      "eight" =&gt; 8,
      "nine" =&gt; 9
    }

    if String.length(line) &lt; 3 do
      nil
    else
      splits =
        numbers
        |&gt; Enum.map(fn number -&gt;
          split = String.split(line, number)
          {number, split |&gt; Enum.map(&amp;(&amp;1 |&gt; String.length()))}
        end)
        |&gt; Enum.filter(&amp;(&amp;1 |&gt; elem(1) |&gt; Enum.count() &gt; 1))


      number_word =
        splits
        |&gt; Enum.sort_by(fn split -&gt;
          split |&gt; elem(1) |&gt; List.first()
        end)
        |&gt; Enum.at(0)

      res =
        if is_tuple(number_word) do
          Map.get(numbers_map, number_word |&gt; elem(0))
        else
          nil
        end

      res
    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="309599" 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-2023-day-1/60073/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-309599" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="309599"
                     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="309607" data-post-id="309607">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I took a similar approach to <a class="mention" href="/u/mruoss" rel="nofollow">@mruoss</a> and used <code>String.reverse</code> for the “find things starting from the end” part.</p>
<p>However, I used <code>Regex</code> instead of binary matching, because I’ve never had a client requirement of “can you treat <code>one</code> like <code>1</code>” not turn into “oh yeah it might be spelled <code>oNe</code> too” eventually <img src="https://forum.elixirforum.com/images/emoji/apple/stuck_out_tongue.png?v=15" title=":stuck_out_tongue:" class="emoji" alt=":stuck_out_tongue:" loading="lazy" width="20" height="20"></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Day1Part2 do
  def read(filename) do
    File.stream!(filename)
    |&gt; Stream.map(&amp;String.trim/1)
    |&gt; Stream.map(&amp;get_digits/1)
    |&gt; Stream.map(&amp;to_integer/1)
  end

  defp get_digits(s) do
    {get_front_digit(s), get_back_digit(s)}
  end

  defp get_front_digit(s) do
    ~r{\d|one|two|three|four|five|six|seven|eight|nine|zero}
    |&gt; Regex.run(s, capture: :first)
    |&gt; List.first()
  end

  defp get_back_digit(s) do
    ~r{\d|orez|enin|thgie|neves|xis|evif|ruof|eerht|owt|eno}
    |&gt; Regex.run(String.reverse(s), capture: :first)
    |&gt; List.first()
    |&gt; String.reverse()
  end

  defp to_integer({first, last}) do
    10 * parse_one(first) + parse_one(last)
  end

  @valid_integers %{
    "0" =&gt; 0,
    "zero" =&gt; 0,
    "1" =&gt; 1,
    "one" =&gt; 1,
    "2" =&gt; 2,
    "two" =&gt; 2,
    "3" =&gt; 3,
    "three" =&gt; 3,
    "4" =&gt; 4,
    "four" =&gt; 4,
    "5" =&gt; 5,
    "five" =&gt; 5,
    "6" =&gt; 6,
    "six" =&gt; 6,
    "7" =&gt; 7,
    "seven" =&gt; 7,
    "8" =&gt; 8,
    "eight" =&gt; 8,
    "9" =&gt; 9,
    "nine" =&gt; 9
  }

  defp parse_one(s), do: Map.fetch!(@valid_integers, s)
end

Day1Part2.read("input.txt")
|&gt; Enum.sum()
|&gt; IO.inspect()
</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="309607" 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-2023-day-1/60073/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-309607" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="309607"
                     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="309608" data-post-id="309608">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group quote-modified" data-username="seeplusplus" data-post="16" data-topic="60073">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/seeplusplus/48/32772_2.png" class="avatar"> seeplusplus:</div>
<blockquote>
<p>Any insight into idioms/patterns to improve this would be great.</p>
</blockquote>
</aside>
<p>Here’s one idiom opportunity I notice:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def search_for_written_number(line) do
  numbers = [...]
  numbers_map = %{...}
end
</code></pre>
<p>These variables aren’t exactly variable—<s>but as written, they get allocated every time the function is called</s> <em><strong>edit:</strong> incorrect, see <a href="https://forum.elixirforum.com/t/advent-of-code-2023-day-1/60073/20" rel="nofollow">this reply</a></em>. This is a good use-case for <a href="https://hexdocs.pm/elixir/Module.html#module-custom-attributes" rel="noopener nofollow ugc">using custom module attributes</a> as the idiomatic equivalent of “constants” in Elixir:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">@numbers = [...]
@numbers_map = %{...}

def search_for_written_number(line) do
  # Reference @numbers
</code></pre>
<p>I used them in my solution to do metaprogramming outside function bodies, but they’re equally useful inside functions and very commonly used for exactly this sort of thing!</p>
<p>Idiomatically they are declared towards the top-level. This makes it easier to see and change static data like this upfront.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="309608" 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-2023-day-1/60073/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-309608" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="309608"
                     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="309611" data-post-id="309611">
  <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
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>That’s cool, I didn’t think of searching from the back rather than doing a first pass to convert to numbers. Doing a quick comparison with the first pass approach, first pass is slightly faster, but there’s not much in it. It might depend on string length, too.</p>
<aside class="quote no-group" data-username="al2o3cr" data-post="17" data-topic="60073">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/48/3457_2.png" class="avatar"> al2o3cr:</div>
<blockquote>
<p>I’ve never had a client requirement</p>
</blockquote>
</aside>
<p>Did any of your clients ask you to spend your free time solving coding puzzles? <img src="https://forum.elixirforum.com/images/emoji/apple/stuck_out_tongue.png?v=15" title=":stuck_out_tongue:" class="emoji" alt=":stuck_out_tongue:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="309611" 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-2023-day-1/60073/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-309611" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="309611"
                     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="309612" data-post-id="309612">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group quote-modified" data-username="christhekeele" data-post="18" data-topic="60073">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/christhekeele/48/1039_2.png" class="avatar"> christhekeele:</div>
<blockquote>
<p>These variables aren’t exactly variable—but as written, they get allocated every time the function is called.</p>
</blockquote>
</aside>
<p>This is not generally true in Elixir - all of the references in this example compile to a single entry in the <code>LitT</code> literal chunk:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Foo do
  @attr_version %{
    a: 1,
    b: 2,
    c: 3
  }

  def attr_lookup(x), do: Map.get(@attr_version, x)

  def inline_lookup(x), do: Map.get(%{a: 1, b: 2, c: 3}, x)

  def variable_lookup(x) do
    map = %{
      a: 1,
      b: 2,
      c: 3
    }

    Map.get(map, x)
  end
end
</code></pre>
<p>The Elixir compiler can safely make this optimization since values can’t ever be mutated - this is different from languages like Ruby where a literal <em>constructed</em> inside a method has to be distinct since it could be subsequently changed. For instance:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">class Foo
  ALWAYS_THE_SAME = {a: 1, b: 2, c: 3}

  def self.as_constant
    ALWAYS_THE_SAME
  end

  def self.as_local
    {a: 1, b: 2, c: 3}
  end
end

puts Foo.as_constant.object_id == Foo.as_constant.object_id
puts Foo.as_local.object_id == Foo.as_local.object_id
</code></pre>
<p>prints <code>true</code> followed by <code>false</code>, because the result from <code>as_local</code> is a different object every time.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="309612" 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-2023-day-1/60073/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-309612" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="309612"
                     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="309613" data-post-id="309613">
  <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
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Welcome to ElixirForum <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<aside class="quote no-group" data-username="Askath" data-post="11" data-topic="60073">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/askath/48/32238_2.png" class="avatar"> Askath:</div>
<blockquote>
<pre data-code-wrap="elixir"><code class="lang-elixir">      {"eighthree", 83},
      {"eightwo", 82},
      {"fiveight", 58},
      {"threeight", 38},
      {"sevenine", 79},
      {"oneight", 18},
      {"twone", 21},
</code></pre>
</blockquote>
</aside>
<p>I handn’t considered hardcoding all the overlaps <img src="https://forum.elixirforum.com/images/emoji/apple/smile.png?v=15" title=":smile:" class="emoji" alt=":smile:" loading="lazy" width="20" height="20"></p>
<p>A couple of functions that might be useful to simplify:</p>
<ul>
<li><a href="https://hexdocs.pm/elixir/File.html#read!/1" rel="noopener nofollow ugc"><code>File.read!/1</code></a></li>
<li><a href="https://hexdocs.pm/elixir/Enum.html#sum/1" rel="noopener nofollow ugc"><code>Enum.sum/1</code></a></li>
</ul> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="309613" 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-2023-day-1/60073/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-309613" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="309613"
                     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/60073/load_more?page=3">Load more posts (26 remaining)</a>
</div></template></turbo-stream>