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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>This one was a real bear for me.  I think I’m not yet thinking in proper functional terms, when I see some of the short elegant solutions.  Here’s mine:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Day10 do

  @input [
    # original array of numbers given, removed here for brevity
  ] |&gt; Enum.sort

  @full_input @input ++ [List.last(@input) + 3]

  def part1() do
    jumps = count_jumps(@full_input, 0, %{})
    jumps[1] * jumps[3]
  end

  def part2() do
    find_ways_to_each([0|@full_input], %{0 =&gt; 1})[List.last(@full_input)]
  end

  defp count_jumps([next|rest], last, acc) do
    diff = next - last
    old = Map.get(acc, diff, 0)
    count_jumps(rest, next, Map.put(acc, diff, old + 1))
  end
  defp count_jumps([], _, acc), do: acc

  defp find_ways_to_each([here|rest], counts) do
    new_counts =
      rest
      |&gt; Enum.take(3)
      |&gt; Enum.filter(&amp;(&amp;1 &lt;= here + 3))
      |&gt; add_to_map(counts[here], counts)
    find_ways_to_each(rest, new_counts)
  end
  defp find_ways_to_each([], counts), do: counts

  defp add_to_map([target|rest], ways_here, counts) do
    add_to_map(rest, ways_here,
               Map.update(counts, target, ways_here, &amp;(&amp;1 + ways_here)))
  end
  defp add_to_map([], _, counts), do: counts
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="197471" 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-2020-day-10/36119/32">Post #31</a>
	                </div>
	            </div>
              <div id="likers-container-197471" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="197471"
                     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 #31"></div>
  </section>
</div>
    <div class="postbit" id="198520" data-post-id="198520">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Similar approach.</p>
<p>What I did, actually, was to create a new array which contained the differences between numbers where 1-differenced numbers were the most important:<br>
[(0), 1, 4, 5, 6, 7, 10, 11, 12, 15, 16, 19] turns into [1, 3, 1, 1, 1, 3, 1, 1, 3, 1, 3]</p>
<p>Now the times you can remodel two or more contiguous 1’s in the second array is your solution:</p>
<p>1, 1, 1 turns into [2, 1], [1, 2] and [3]  (4 different ways)<br>
1, 1 turns into [2] (2 different ways)<br>
Now, 4*2 = 8<br>
It gets tough when you have to remodel five or more contiguous 1’s</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="198520" 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-2020-day-10/36119/33">Post #32</a>
	                </div>
	            </div>
              <div id="likers-container-198520" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="198520"
                     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>