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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="hauleth" data-post="11" data-topic="35931">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hauleth/48/18942_2.png" class="avatar"> hauleth:</div>
<blockquote>
<p><code>    |&gt; Enum.map(&amp;String.trim/1)</code></p>
</blockquote>
</aside>
<p>Is this run through the list even needed? (if so you could always just make this part of <code>parse/1</code>, just curious)</p>
<p>I can’t believe I have been doing this for this long without knowing about <code>binary_part/3</code> - thanks!</p> 
	            </div>

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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Aetherus" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Aetherus/120/17203_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Aetherus
                    <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>The <code>&lt;&lt;^char &lt;- pass&gt;&gt;</code> part is cool! Thank you for showing me another thing in Elixir that I don’t know <img src="https://forum.elixirforum.com/images/emoji/apple/heavy_heart_exclamation.png?v=15" title=":heavy_heart_exclamation:" class="emoji" alt=":heavy_heart_exclamation:" 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="196198" 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-2020-day-2/35931/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-196198" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="196198"
                     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="196202" data-post-id="196202">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>O(mn) solution.</p>
<p>solution 1</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Advent.Day2 do
  import String, only: [split: 2, to_integer: 1, at: 2]

  def start(part, file \\ "/tmp/data.txt") do
    File.read!(file)
    |&gt; String.split("\n")
    |&gt; Enum.reduce(0, fn line, acc -&gt; acc + is_valid(line, part) end)
  end

  defp is_valid(line, _part) when line in ["", nil], do: 0
  defp is_valid(line, :part1) do
    [min, max, letter, _, passwd] = split(line, ["-", " ", ":"])
    &lt;&lt;word::utf8&gt;&gt; = letter
    count = Enum.count(to_charlist(passwd), fn x -&gt; x == word end)
    ((to_integer(min) &lt;= count) and (count &lt;= to_integer(max))) &amp;&amp; 1 || 0
  end
  defp is_valid(line, :part2) do
    [p1, p2, letter, _, passwd] = split(line, ["-", " ", ":"])
    case {at(passwd, to_integer(p1) - 1) == letter, at(passwd, to_integer(p2) - 1) == letter} do
       {true, false} -&gt; 1
       {false, true} -&gt; 1
       _ -&gt; 0
    end
  end

end
</code></pre>
<p>antoher solution for part1</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Advent.Day2b do
  import String, only: [split: 2, to_integer: 1, replace: 3, at: 2]

  def start(part, file \\ "/tmp/data.txt") do
    File.read!(file)
    |&gt; split("\n")
    |&gt; Enum.reduce(0, fn line, acc -&gt; acc + is_valid(line, part) end)
  end

  defp is_valid(line, _) when line in ["", nil], do: 0
  defp is_valid(line, :part1) do
    [min, max, letter, _, passwd] = split(line, ["-", " ", ":"])
    count = byte_size(passwd) - byte_size(replace(passwd, letter, ""))
    ((to_integer(min) &lt;= count) and (count &lt;= to_integer(max))) &amp;&amp; 1 || 0
  end
  defp is_valid(line, :part2) do
    [p1, p2, letter, _, passwd] = split(line, ["-", " ", ":"])
    case {at(passwd, to_integer(p1) - 1) == letter, at(passwd, to_integer(p2) - 1) == letter} do
       {true, false} -&gt; 1
       {false, true} -&gt; 1
       _ -&gt; 0
    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="196202" 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-2020-day-2/35931/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-196202" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="196202"
                     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="196258" data-post-id="196258">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>What is the benefit of duing</p>
<aside class="quote no-group" data-username="hauleth" data-post="11" data-topic="35931">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hauleth/48/18942_2.png" class="avatar"> hauleth:</div>
<blockquote>
<p><code>count = for &lt;&lt;^char &lt;- pass&gt;&gt;, reduce: 0, do: (n -&gt; n + 1)</code></p>
</blockquote>
</aside>
<p>over something like</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">pass
|&gt; String.codepoints()
|&gt; Enum.count(&amp; &amp;1 == char)
</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="196258" 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-2020-day-2/35931/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-196258" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="196258"
                     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="196275" data-post-id="196275">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Codepoints is slower as it needs to understand UTF-8 encoding. Mine is just passing over all bytes in the binary. Also mine does everything in one pass instead of 2 passes (one pass over the binary to construct list and another over the list to count occurrences). Not that this matter in this case, but I didn’t wanted to do 2 passes.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="196275" 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-2020-day-2/35931/27">Post #26</a>
	                </div>
	            </div>
              <div id="likers-container-196275" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="196275"
                     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="196299" data-post-id="196299">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I was trying this today, but for take the total in the final I was unable.<br>
someone could help me with this?<br>
trying this</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Day2 do
  @type claim :: String.t
  @type parsed_claim :: list
  @spec parse_claim(binary) :: :ok

  @moduledoc """
  Advent of Code `Day2`.
  """

  def values do
      values =
        File.read!("lib/input.txt")
        |&gt; String.trim()
        |&gt; String.split("\n")
        |&gt; Enum.map(&amp;parse_claim/1)
  end

  @spec parse_claim(claim) :: parsed_claim
  def parse_claim(string) when is_binary(string) do
    string
    |&gt; String.split(["-", " ", ":", " "], trim: true)
    |&gt; claimed_values()
  end


  def claimed_values(parsed_claims) do

    [min, max, char_str, str] = parsed_claims

      r_min = String.to_integer(min)
      r_max = String.to_integer(max)

      #validate password

      if str |&gt; String.contains?(char_str) do

        char_key = take_char(char_str)
        list_char = take_char(str)

        calculate_password([r_min, r_max, char_key, list_char])
      end
  end

  defp take_char(char) do
    char
    |&gt; String.graphemes
    |&gt; Enum.map(&amp;String.to_charlist/1)
  end

  defp calculate_password([min, max, char_key, list_char]) do
    count = Enum.count(list_char, &amp;(&amp;1 == char_key))

    if ((count &gt;= min) &amp;&amp; (count &lt;= max)), do: total + 1, else: total
  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="196299" 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-2/35931/28">Post #27</a>
	                </div>
	            </div>
              <div id="likers-container-196299" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="196299"
                     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 #27"></div>
  </section>
</div>
    <div class="postbit" id="196315" data-post-id="196315">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Aetherus" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Aetherus/120/17203_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Aetherus
                    <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>Sorry for being late (I was sleeping).</p>
<p>I’m trying your solution, and the first error I found is in this function:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defp calculate_password([min, max, char_key, list_char]) do                                                    
  count = Enum.count(list_char, &amp;(&amp;1 == char_key))                                                             
                                                                                                                 
  if ((count &gt;= min) &amp;&amp; (count &lt;= max)), do: total + 1, else: total
  #                                          ^^^^^            ^^^^^
end
</code></pre>
<p>The variable <code>total</code> is not defined. If you want a global variable, well, there’s no variable variables of any kind in Elixir. So, you have to use some kind of <code>reduce</code>.</p>
<p><strong>UPDATE 1</strong></p>
<p>The <code>take_char/1</code> function doesn’t make sense to me. It returns a list of lists with each sub-list contains only 1  integer (the codepoint of the character). I think the <code>|&gt; Enum.map(&amp;String.to_charlist/1)</code> can be dropped. By the way, you can directly compare to strings/binaries without converting them to charlists.</p> 
	            </div>

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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thank you for your reply Aetherus:<br>
I realized doing this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule Day2 do
    @moduledoc """
  Advent of Code `Day2`.
  """

  def run do
    File.read!("lib/input.txt")
    |&gt; String.split("\n", trim: true)
    |&gt; Enum.map(&amp;parse_claim/1)
  end
  @doc """
  Reads the file and execute the logic and returns the result

  ## Examples

    iex&gt; Day2.values
    636
  """
  def part1 do
    run()
    |&gt; Enum.map(fn [min, max, key, password] -&gt;
      check_part1?(String.to_integer(min), String.to_integer(max), key, password)
    end)
    |&gt; Enum.count(&amp;(&amp;1))
  end

  def part2 do
    run()
    |&gt; Enum.map(fn [min, max, key, password] -&gt;
      check_part2?(String.to_integer(min), String.to_integer(max), key, password)
    end)
    |&gt; Enum.count(&amp;(&amp;1))
  end

  @doc """
  Parses a claim.

  ## Examples

    iex&gt; Day2.parse_claim("1-3 a: abcde")
    ["1", "3", "a", "abcde"]

  """
  def parse_claim(list_string) when is_binary(list_string) do
    list_string
    |&gt; String.split(["-", " ", ":", " "], trim: true) #  ["1", "3", "p", "pppp"], [...]
  end

  defp check_part1?(r_min, r_max, key, password) do
    if  String.contains?(password, key) do
      count =
        password
        |&gt; String.graphemes
        |&gt; Enum.filter(fn x -&gt; x == key end)
        |&gt; Enum.count

      #count &gt;= r_min &amp;&amp; count &lt;= r_max
      count in r_min..r_max
    end
  end

  defp check_part2?(r_min, r_max, key, password) do
    if  String.contains?(password, key) do
        list =
          password
          |&gt; String.graphemes

        x_min = list |&gt; Enum.at(r_min - 1) == key
        x_max = list |&gt; Enum.at(r_max - 1) == key

        x_min  != x_max
    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="196414" 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-2020-day-2/35931/30">Post #29</a>
	                </div>
	            </div>
              <div id="likers-container-196414" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="196414"
                     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 #29"></div>
  </section>
</div>
    <div class="postbit" id="196458" data-post-id="196458">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>My approach, as I started learning Erlang… <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">-module(day2).
-export([run/0]).

run()-&gt;
    ParsedLines = load_file("day2input.txt"),
    {part1(ParsedLines), part2(ParsedLines)}.

part1(ParsedLines)-&gt;
    ValidLines = [ Line || Line &lt;- ParsedLines, is_valid1(Line)],
    length(ValidLines).

part2(ParsedLines)-&gt;
    ValidLines = [ Line || Line &lt;- ParsedLines, is_valid2(Line)],
    length(ValidLines).

is_valid1({From, To, Char, Pw}) -&gt;
    N = length([[X] || X &lt;- Pw, [X] =:= Char]),
    (N &gt;= From) and (N =&lt; To).

is_valid2({Idx1, Idx2, Char, Pw}) -&gt;
    (string:slice(Pw, Idx1-1, 1) =:= Char) xor (string:slice(Pw, Idx2-1, 1) =:= Char).

load_file(Filename)-&gt;
    {ok, Binary} = file:read_file(Filename),
    StringContent = unicode:characters_to_list(Binary),
    [ parse(Line) || Line &lt;- string:tokens(StringContent, "\n")]. 

parse(Line)-&gt;
    {ok, MP} = re:compile("([0-9]+)-([0-9]+) ([a-z]): ([a-z]+)"),
    {_,[_,From, To, Char, Pw]} = re:run(Line, MP),
    {extract_num(Line, From), extract_num(Line, To), extract_str(Line, Char), extract_str(Line, Pw)}.

extract_str(String, {Start, End})-&gt;
    string:slice(String, Start, End).

extract_num(String, {Start, End})-&gt;
    Str = string:slice(String, Start, End),
    {Int, _} = string:to_integer(Str),
    Int.
</code></pre>
<p>For part 1 I did a list comprehension on the string to get the number of occurrences.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="196458" 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-2020-day-2/35931/31">Post #30</a>
	                </div>
	            </div>
              <div id="likers-container-196458" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="196458"
                     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 #30"></div>
  </section>
</div>
    <div class="postbit" id="196522" data-post-id="196522">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>For the first part I did the following knowing that splitting a string with non-existing character leave the string itself and if it’s present n times it gives n+1 chunks:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defp valid?({range, letter, password}) do
  chunks =
    password
    |&gt; String.split(letter)
    |&gt; Enum.count()
  (chunks - 1) in range
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="196522" 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-2020-day-2/35931/32">Post #31</a>
	                </div>
	            </div>
              <div id="likers-container-196522" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="196522"
                     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>
</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/35931/load_more?page=4">Load more posts (3 remaining)</a>
</div></template></turbo-stream>