<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="234151" data-post-id="234151">
  <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">
								<aside class="quote no-group" data-username="stevensonmt" data-post="30" data-topic="44230">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stevensonmt/48/20503_2.png" class="avatar"> stevensonmt:</div>
<blockquote>
<p>so negation in erlang flips all the infinite preceding zeroes? Is there a practical reason for that? Is it just to avoid the need for distinct sized integer types like u8, u16, i32, etc?</p>
</blockquote>
</aside>
<p>Yes, that is the reason. Since Erlang has no static types, it seems to be the only reasonable way to implement integers of arbitrary size.</p>
<aside class="quote no-group" data-username="stevensonmt" data-post="30" data-topic="44230">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/stevensonmt/48/20503_2.png" class="avatar"> stevensonmt:</div>
<blockquote>
<p>Would you always get an accurate answer by masking with ones in all places up to the bitsize you need? Would it be safe to just mask by 4294967295 unless your values exceed u32 max size?</p>
</blockquote>
</aside>
<p>Yes. No. You must mask with a mask of the correct size.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="234151" 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-2021-day-3/44230/32">Post #31</a>
	                </div>
	            </div>
              <div id="likers-container-234151" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="234151"
                     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="234152" data-post-id="234152">
  <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>Many thanks for the kind explanation.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="234152" 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-2021-day-3/44230/33">Post #32</a>
	                </div>
	            </div>
              <div id="likers-container-234152" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="234152"
                     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 #32"></div>
  </section>
</div>
    <div class="postbit" id="234215" data-post-id="234215">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hey all, for those that want to watch a recap of Jose’s Day 3 stream, I edited something together in a shorter format: <a href="https://www.youtube.com/watch?v=SGQFAn4HtAI" rel="noopener nofollow ugc">https://www.youtube.com/watch?v=SGQFAn4HtAI</a>. I’ve done this for the first 2 days, and I’m also doing this for all the upcoming AoC days!</p>
<p>Each video has:</p>
<ul>
<li>Chapter markers for every single one so you could get a rough overview of the video and can skip to different parts if you wish.</li>
<li>Twitch chat screenshots for additional context</li>
<li>Jose’s planning process</li>
<li>Errors Jose runs into with explanations (if available) on how to resolve it. He’s a good speaker so usually more context is provided.</li>
</ul>
<p>Let me know what you want to be added/improved to make this easier to digest. I hope these will be useful!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="234215" 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-2021-day-3/44230/34">Post #33</a>
	                </div>
	            </div>
              <div id="likers-container-234215" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="234215"
                     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 #33"></div>
  </section>
</div>
    <div class="postbit" id="234223" data-post-id="234223">
  <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">
								<p>part 1:</p>
<p><a href="https://github.com/rugyoga/aoc2021/blob/main/day3.exs" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/rugyoga/aoc2021/blob/main/day3.exs</a></p>
<p>part 2:</p>
<p><a href="https://github.com/rugyoga/aoc2021/blob/main/day3b.exs" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/rugyoga/aoc2021/blob/main/day3b.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="234223" 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-2021-day-3/44230/35">Post #34</a>
	                </div>
	            </div>
              <div id="likers-container-234223" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="234223"
                     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 #34"></div>
  </section>
</div>
    <div class="postbit" id="270143" data-post-id="270143">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I did it with bitstrings. But I wasn’t clever enough to notice you can skip calculating eplison.</p>
<p>Also, yes I know it’s 2022. Had submarine problems.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  def part2(input) do
    oxygen_generator_rating = find_rating2(input, 0, :most)
    co2_scrubber_rating = find_rating2(input, 0, :least)
    oxygen_generator_rating * co2_scrubber_rating
  end

  defp find_rating2([bits], _bits_seen, _mode) do
    &lt;&lt;value::size(bit_size(bits))&gt;&gt; = bits
    value
  end

  defp find_rating2(values, bits_seen, mode) do
    bit = find_common(values, bits_seen, mode)

    values
    |&gt; filter_by_bit(bits_seen, bit)
    |&gt; find_rating2(bits_seen + 1, mode)
  end

  defp find_common(values, bits_seen, mode) do
    {zeros, ones} =
      values
      |&gt; Enum.map(fn &lt;&lt;_::size(bits_seen), bit::1, _rest::bits&gt;&gt; -&gt; bit end)
      |&gt; Enum.reduce({_zeros = 0, _ones = 0}, fn
        0, {zeros, ones} -&gt; {zeros + 1, ones}
        1, {zeros, ones} -&gt; {zeros, ones + 1}
      end)

    case mode do
      :most -&gt; if zeros &lt;= ones, do: 1, else: 0
      :least -&gt; if zeros &lt;= ones, do: 0, else: 1
    end
  end

  defp filter_by_bit(values, num_prev_bits, bit) do
    Enum.filter(values, &amp;match?(&lt;&lt;_::size(num_prev_bits), ^bit::1, _rest::bits&gt;&gt;, &amp;1))
  end
</code></pre>
<p><a href="https://git.adamu.jp/adam/AdventOfCode/src/branch/main/2021/day3.exs" class="onebox" target="_blank" rel="noopener nofollow ugc">https://git.adamu.jp/adam/AdventOfCode/src/branch/main/2021/day3.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="270143" 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-2021-day-3/44230/36">Post #35</a>
	                </div>
	            </div>
              <div id="likers-container-270143" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="270143"
                     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>