<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="349360" data-post-id="349360">
  <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>Do you think that text is a diversion for AI? It certainly persuaded my natural intelligence to implement the naive solution for part 1.</p>
<p>I got stuck on part 2, I had a vague idea of using memoization but couldn’t figure it out, and had to take a sneak peek here to push me in the right direction. I learned from previous years that stubbornly trying to work out everything from first principles isn’t necessarily the best way to learn.</p>
<p>It turned out to be very simple, after getting my head around what was required. No memoization needed, just have to keep track of how many of each stone there are each blink.</p>
<aside class="quote no-group" data-username="AoC">
<div class="title">
<div class="quote-controls"></div>
 AoC:</div>
<blockquote>
<p>No matter how the stones change, their <strong>order is preserved</strong>, and they stay on their perfectly straight line.</p>
</blockquote>
</aside>
<p><img src="https://forum.elixirforum.com/images/emoji/apple/roll_eyes.png?v=15" title=":roll_eyes:" class="emoji only-emoji" alt=":roll_eyes:" loading="lazy" width="20" height="20"></p>
<aside class="quote no-group" data-username="mexicat" data-post="4" data-topic="68028">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mexicat/48/16175_2.png" class="avatar"> mexicat:</div>
<blockquote>
<p>order doesn’t matter</p>
</blockquote>
</aside>
<p><img src="https://forum.elixirforum.com/images/emoji/apple/heart_hands.png?v=15" title=":heart_hands:" class="emoji only-emoji" alt=":heart_hands:" loading="lazy" width="20" height="20"></p>
<p>My answer:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def blink(stones, 0), do: stones |&gt; Map.values() |&gt; Enum.sum()

def blink(stones, times) do
  stones
  |&gt; Enum.reduce(%{}, fn
    {0, count}, next -&gt;
      Map.update(next, 1, count, &amp;(&amp;1 + count))

    {stone, count}, next -&gt;
      string = Integer.to_string(stone)
      size = byte_size(string)

      if rem(size, 2) == 0 do
        {a, b} = String.split_at(string, div(size, 2))

        next
        |&gt; Map.update(String.to_integer(a), count, &amp;(&amp;1 + count))
        |&gt; Map.update(String.to_integer(b), count, &amp;(&amp;1 + count))
      else
        Map.update(next, stone * 2024, count, &amp;(&amp;1 + count))
      end
  end)
  |&gt; blink(times - 1)
end
</code></pre>
<aside class="quote no-group" data-username="antoine-duchenet" data-post="1" data-topic="68028">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/antoine-duchenet/48/27136_2.png" class="avatar"> antoine-duchenet:</div>
<blockquote>
<p>A virtual part 3 with 1000 blinks instead of 75 takes “only” ~5475ms to run.</p>
</blockquote>
</aside>
<p>1500ms here.</p>
<p><a href="https://git.adamu.jp/adam/AdventOfCode/src/branch/main/2024/day11.exs" class="onebox" target="_blank" rel="noopener nofollow ugc">https://git.adamu.jp/adam/AdventOfCode/src/branch/main/2024/day11.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="349360" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/advent-of-code-2024-day-11/68028/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-349360" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349360"
                     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="349365" data-post-id="349365">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>That would make sense yes !</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="349365" 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-11/68028/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-349365" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349365"
                     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="349372" data-post-id="349372">
  <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">
								<aside class="quote no-group" data-username="jarlah" data-post="6" data-topic="68028">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jarlah/48/24789_2.png" class="avatar"> jarlah:</div>
<blockquote>
<p>when it comes to 40ms or whatever for run times, do people run the solutions in a non test environment or release or something</p>
</blockquote>
</aside>
<p>All of my answers are standalone scripts and the measurement code is right there in the script. It uses :timer.tc and doesn’t include parsing the input, so could produce lower times than others who include that. It’s mostly just for me to see what sort of ballpark the answer is in terms of speed. A bit academic for today where part 2 would probably never complete using the initial implementation…</p> 
	            </div>

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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>btw i asked perplexity to make a graphical representation of the process for the two simple numbers “125 17”, based on the recursive approach i used. It failed, tremendously. It doesn’t even surprise me any more that if you tell AI 1+1 is 2.. it still manages to tell you it can be 6. Anyway, end of rant for THAT.</p>
<p>In this example we blink 2 times. I made two diagrams showing whats happening, for the interested ones among us. When i work with tiles, i usually make a map printer, to print the map before and after. For this task this was a bit hard ..</p>
<p>so for the simple example “125 17”, we get:</p>
<p>125:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">          [125]
            |
        [253000]
            |
         /       \
     [253]       [0]
</code></pre>
<p>17:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">          [17]
            |
         /     \
      [1]      [7]
        |        |
     [2024]   [14168]
</code></pre>
<p>i double checked this in my code</p>
<p>count for 253: 1<br>
count for 0: 1<br>
count for 253000: 2<br>
count for 125: 2<br>
total count for stone 125: 2<br>
count for 2024: 1<br>
count for 1: 1<br>
count for 14168: 1<br>
count for 7: 1<br>
count for 17: 2<br>
total count for stone 17: 2</p>
<p>The number after the colon is the accumulated count of stones.</p>
<p>I think its fun to dig into things like that, understand it fully, deeply</p>
<p>If we blink three times we get something like this</p>
<p>125:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">          [125]
            |
        [253000]
            |
         /       \
     [253]       [0]
      /
   [512072]
</code></pre>
<p>17:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">          [17]
            |
         /     \
      [1]      [7]
        |        \
     [2024]    [14168]
      /   \         \
   [20]  [24]   [28676032]
</code></pre>
<p>which is 5</p>
<p>count for 512072: 1<br>
count for 253: 1<br>
count for 1: 1<br>
count for 0: 1<br>
count for 253000: 2<br>
count for 125: 2<br>
total count for stone 125: 2<br>
count for 20: 1<br>
count for 24: 1<br>
count for 2024: 2<br>
count for 1: 2<br>
count for 28676032: 1<br>
count for 14168: 1<br>
count for 7: 1<br>
count for 17: 3<br>
total count for stone 17: 3</p>
<p>PS! For the AI rant i was asking it to give me the tree for a bigger number of blinks .. so i asked it after some infuriating time to use 2 blinks instead and even then it failed so the diagram above is manipulated to be correct by a human.. me</p> 
	            </div>

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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="bjorng" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bjorng/120/13187_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  bjorng
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Erlang Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Here is my solution. The combined time for both parts is 0.07 seconds.</p>
<p><a href="https://github.com/bjorng/advent-of-code/blob/main/2024/day11/lib/day11.ex" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/bjorng/advent-of-code/blob/main/2024/day11/lib/day11.ex</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="349414" 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-11/68028/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-349414" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349414"
                     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="349424" data-post-id="349424">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>seems you did mostly the same as me only with a much more terser syntax. And you only cache in one place. In my code its caching aaaaalll over the place lol . i have yet to remove some part of this caching</p>
<p>EDIT: finally .. so, no need to cache stone splits . .they are so insanely fast anyway. One this line <a href="https://github.com/jarlah/advent_of_code/blob/master/lib/2024/day_11/Part1.ex#L57" rel="noopener nofollow ugc">https://github.com/jarlah/advent_of_code/blob/master/lib/2024/day_11/Part1.ex#L57</a> i had a call to another function that used the memo cache to avoid splitting the number <img src="https://forum.elixirforum.com/images/emoji/apple/smiley.png?v=15" title=":smiley:" class="emoji" alt=":smiley:" loading="lazy" width="20" height="20"> lol</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="349424" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/advent-of-code-2024-day-11/68028/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-349424" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349424"
                     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="349427" data-post-id="349427">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>LOC: 12</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Aoc2024.Day11 do
  def part1(file), do: main(file, 25)
  def part2(file), do: main(file, 75)
  def main(file, n), do: file |&gt; ints() |&gt; Map.new(&amp;{String.to_integer(&amp;1), 1}) |&gt; count(n)
  def ints(file), do: file |&gt; File.read!() |&gt; String.split(" ", trim: true)
  def count(ints, 0), do: Enum.sum_by(ints, fn {_, v} -&gt; v end)
  def count(ints, depth), do: ints |&gt; Enum.reduce(%{}, &amp;blink/2) |&gt; count(depth - 1)
  def blink({x, n}, acc), do: Enum.reduce(f(x), acc, &amp;Map.update(&amp;2, &amp;1, n, fn y -&gt; y + n end))
  def f(0), do: [1]
  def f(x), do: if(rem(l = length(d = Integer.digits(x)), 2) == 0, do: s(d, l), else: [x * 2024])
  def s(d, l), do: d |&gt; Enum.split(div(l, 2)) |&gt; Tuple.to_list() |&gt; Enum.map(&amp;Integer.undigits/1)
end
</code></pre>
<p>Had to go back to the drawing board on this one. My first approach (stack-based) didn’t finish for part 2.</p>
<p>EDIT: changed a function name (no change in LOC).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="349427" 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-11/68028/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-349427" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349427"
                     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="349429" data-post-id="349429">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>PSA: If you’re using Elixir 1.18, now there’s:</p>
<ul>
<li><a href="https://hexdocs.pm/elixir/1.18.0-rc.0/Enum.html#sum_by/2" rel="noopener nofollow ugc"><code>Enum.sum_by/2</code></a></li>
</ul>
<p>No more <code>Enum.reduce(enum, 0, &amp;(&amp;1 + &amp;2))</code> <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="349429" data-batch-url="/posts/batch_likers">
                        6
                      </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-11/68028/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-349429" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349429"
                     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="349434" data-post-id="349434">
  <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>++ for not using a cache/memoization <em>per se</em>. I feel like I learned something from this solution.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="349434" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/advent-of-code-2024-day-11/68028/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-349434" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349434"
                     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="349437" data-post-id="349437">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Seriously short of time to do this today, so I used Memoize rather than roll my own memoization implementation, if I get a chance I’ll re-write using a hand rolled cache.</p>
<p>Still happy with the solution and run-time though.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">Solution for 2024 day 11
part_one: 193607 in 12.01ms
part_two: 229557103025807 in 252.98ms

Name               ips        average  deviation         median         99th %
part_two        7.63 K      131.09 μs    ±50.31%      123.25 μs      226.81 μs
part_one        7.53 K      132.72 μs    ±54.50%      124.13 μs      231.54 μs

Comparison: 
part_two        7.63 K
part_one        7.53 K - 1.01x slower +1.64 μs
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Aoc2024.Solutions.Y24.Day11 do
  require Integer
  alias AoC.Input

  use Memoize

  def parse(input, _part) do
    Input.read!(input)
    |&gt; String.trim()
    |&gt; String.split(" ", trim: true)
    |&gt; Enum.map(&amp;String.to_integer/1)
  end

  def part_one(problem) do
    Enum.reduce(problem, 0, fn stone, acc -&gt;
      acc + apply_rules(stone, 0, 25)
    end)
  end

  def part_two(problem) do
    Enum.reduce(problem, 0, fn stone, acc -&gt;
      acc + apply_rules(stone, 0, 75)
    end)
  end

  defmemo apply_rules(stone, count, target) do
    if count == target do
      1
    else
      target_stones = rule(stone)

      case target_stones do
        [_first, _second] -&gt;
          Enum.reduce(target_stones, 0, fn stone, acc -&gt;
            acc + apply_rules(stone, count + 1, target)
          end)

        stone -&gt;
          apply_rules(stone, count + 1, target)
      end
    end
  end

  defmemo rule(stone) do
    if stone == 0 do
      1
    else
      stone_string = Integer.to_string(stone)
      digits = String.length(Integer.to_string(stone))

      case Integer.is_even(digits) do
        true -&gt;
          String.split_at(stone_string, div(digits, 2))
          {left, right} = String.split_at(stone_string, div(digits, 2))

          [
            String.to_integer(left),
            String.to_integer(right)
          ]

        _ -&gt;
          stone * 2024
      end
    end
  end

  defmemo split_into_chunks(options) do
    workers = :erlang.system_info(:schedulers_online)
    options_count = Enum.count(options)
    options_per_chunk = :erlang.ceil(options_count / workers)

    Enum.chunk_every(options, options_per_chunk)
  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="349437" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/advent-of-code-2024-day-11/68028/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-349437" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="349437"
                     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/68028/load_more?page=3">Load more posts (15 remaining)</a>
</div></template></turbo-stream>