<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://abirmaj6-naz.github.io/PROTEUS-Pages/feed.xml" rel="self" type="application/atom+xml" /><link href="https://abirmaj6-naz.github.io/PROTEUS-Pages/" rel="alternate" type="text/html" /><updated>2026-03-28T17:00:59+00:00</updated><id>https://abirmaj6-naz.github.io/PROTEUS-Pages/feed.xml</id><title type="html">Test Environment</title><subtitle>Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.</subtitle><author><name>Daniel Birmajer</name></author><entry><title type="html">Project Euler #003: Largest Prime Factor</title><link href="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/project%20euler/post-link-euler-003/" rel="alternate" type="text/html" title="Project Euler #003: Largest Prime Factor" /><published>2026-03-28T00:00:00+00:00</published><updated>2026-03-28T00:00:00+00:00</updated><id>https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/project%20euler/post-link%20euler-003</id><content type="html" xml:base="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/project%20euler/post-link-euler-003/"><![CDATA[<blockquote>
  <p>The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143?</p>
</blockquote>

<h2 id="the-mathematics">The Mathematics</h2>

<p>The <strong>Fundamental Theorem of Arithmetic</strong> guarantees that every integer greater than 1 has a unique prime factorisation. Our strategy is to repeatedly extract the <em>smallest</em> prime factor of <code class="language-plaintext highlighter-rouge">n</code>, yielding each one, until nothing remains. The last factor yielded will be the largest.</p>

<p>The key efficiency insight: if <code class="language-plaintext highlighter-rouge">n</code> has no divisor in the range <code class="language-plaintext highlighter-rouge">[2, √n]</code>, then <code class="language-plaintext highlighter-rouge">n</code> is prime. This bounds our search at <code class="language-plaintext highlighter-rouge">ceil(sqrt(n))</code>, giving <strong>O(√n)</strong> trial divisions per call — fast even for numbers in the hundreds of billions.</p>

<h2 id="the-python-solution">The Python Solution</h2>

<p>The script decomposes the problem into three clean, single-responsibility functions:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="s">"""
Project Euler Problem 3 - Largest Prime Factor.

This module contains functions to find the largest prime factor of a number.
It includes utilities for finding the smallest divisor and generating prime factors.
"""</span>

<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Iterator</span>
<span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="p">(</span><span class="n">ceil</span><span class="p">,</span> <span class="n">sqrt</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">smallest_divisor</span><span class="p">(</span><span class="n">number</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
    <span class="s">"""
    Returns the smallest divisor of number bigger than 1.
    For example 
    smallest_divisor(100) = 2, 
    smallest_divisor(15) = 3, 
    smallest_divisor(125) = 5.
    """</span>
    <span class="k">assert</span> <span class="p">(</span><span class="n">number</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">),</span> <span class="sa">f</span><span class="s">"Not a valid input number = </span><span class="si">{</span><span class="n">number</span><span class="si">}</span><span class="s"> must be &gt; 1"</span>
    <span class="n">upper_bound</span> <span class="o">=</span> <span class="n">ceil</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">number</span><span class="p">))</span>
    <span class="k">if</span> <span class="n">number</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
        <span class="k">return</span> <span class="mi">2</span>
    <span class="k">if</span> <span class="n">number</span> <span class="o">%</span> <span class="mi">3</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
        <span class="k">return</span> <span class="mi">3</span>
    <span class="n">divisors</span> <span class="o">=</span> <span class="p">(</span><span class="n">d</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">upper_bound</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> <span class="k">if</span> <span class="n">number</span> <span class="o">%</span> <span class="n">d</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="k">return</span> <span class="nb">next</span><span class="p">(</span><span class="n">divisors</span><span class="p">)</span>
    <span class="k">except</span> <span class="nb">StopIteration</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">number</span>


<span class="k">def</span> <span class="nf">prime_factors</span><span class="p">(</span><span class="n">number</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Iterator</span><span class="p">[</span><span class="nb">int</span><span class="p">]:</span>
    <span class="s">"""

    :param number: Integer &gt; 1.
    :return: Returns a generator of the prime factors of number.
    """</span>
    <span class="k">if</span> <span class="n">number</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="n">prime</span> <span class="o">=</span> <span class="n">smallest_divisor</span><span class="p">(</span><span class="n">number</span><span class="p">)</span>
        <span class="k">yield</span> <span class="n">prime</span>
        <span class="k">yield</span> <span class="k">from</span> <span class="n">prime_factors</span><span class="p">(</span><span class="n">number</span> <span class="o">//</span> <span class="n">prime</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">answer</span><span class="p">(</span><span class="n">number</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
    <span class="s">"""
    Return the largest prime factor of the given number.

    This function solves Project Euler problem 3 by finding all prime factors
    of the number and returning the largest one.

    Parameters
    ----------
    number : int
        The number to find the largest prime factor of.

    Returns
    -------
    int
        The largest prime factor of the input number.

    Examples
    --------
    &gt;&gt;&gt; answer(13195)
    29
    """</span>
    <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">prime_factors</span><span class="p">(</span><span class="n">number</span><span class="p">))[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>


<span class="k">print</span><span class="p">(</span><span class="n">answer</span><span class="p">(</span><span class="mi">600_851_475_143</span><span class="p">))</span>
</code></pre></div></div>

<h2 id="how-smallest_divisor-works">How <code class="language-plaintext highlighter-rouge">smallest_divisor</code> Works</h2>

<p>The function finds the smallest prime factor of <code class="language-plaintext highlighter-rouge">number</code> in three steps:</p>

<ol>
  <li><strong>Quick checks for 2 and 3.</strong> These cover all even numbers and multiples of 3 up front, before the main loop.</li>
  <li><strong>Odd candidates only.</strong> The generator <code class="language-plaintext highlighter-rouge">range(5, ub + 1, 2)</code> steps by 2, skipping all even numbers. Since 2 has already been ruled out as a factor, no even number can divide <code class="language-plaintext highlighter-rouge">number</code>, so this halves the remaining search space.</li>
  <li><strong>Early exit via <code class="language-plaintext highlighter-rouge">next()</code>.</strong> The generator <code class="language-plaintext highlighter-rouge">g</code> is lazy — it produces candidates on demand. Calling <code class="language-plaintext highlighter-rouge">next(g)</code> retrieves only the <em>first</em> divisor found and stops immediately. If no divisor exists, the <code class="language-plaintext highlighter-rouge">StopIteration</code> exception is caught and <code class="language-plaintext highlighter-rouge">number</code> itself is returned, indicating <code class="language-plaintext highlighter-rouge">number</code> is prime.</li>
</ol>

<h2 id="how-prime_factors-works--recursion-and-yield-from">How <code class="language-plaintext highlighter-rouge">prime_factors</code> Works — Recursion and <code class="language-plaintext highlighter-rouge">yield from</code></h2>

<p><code class="language-plaintext highlighter-rouge">prime_factors</code> is a <strong>recursive generator</strong>. At each call it:</p>

<ol>
  <li>Finds the smallest divisor <code class="language-plaintext highlighter-rouge">p</code> of <code class="language-plaintext highlighter-rouge">number</code> and <code class="language-plaintext highlighter-rouge">yield</code>s it.</li>
  <li>Uses <code class="language-plaintext highlighter-rouge">yield from prime_factors(number // p)</code> to recursively yield all prime factors of the reduced number.</li>
</ol>

<p><code class="language-plaintext highlighter-rouge">yield from</code> is Python 3’s way of delegating to a sub-generator — it forwards every value the recursive call produces directly to the caller, without needing an explicit loop. The recursion bottoms out when <code class="language-plaintext highlighter-rouge">number == 1</code>, at which point the <code class="language-plaintext highlighter-rouge">if number &gt; 1</code> guard is <code class="language-plaintext highlighter-rouge">False</code> and the generator returns.</p>

<p>For example, factorising 12:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>prime_factors(12)  →  yields 2, then delegates to
  prime_factors(6) →  yields 2, then delegates to
    prime_factors(3) →  yields 3, then delegates to
      prime_factors(1) →  base case, stops
</code></pre></div></div>

<p>Result: <code class="language-plaintext highlighter-rouge">[2, 2, 3]</code></p>

<h2 id="type-hints-and-iterator">Type Hints and <code class="language-plaintext highlighter-rouge">Iterator</code></h2>

<p>The signature <code class="language-plaintext highlighter-rouge">def prime_factors(n: int) -&gt; Iterator[int]</code> uses Python’s <code class="language-plaintext highlighter-rouge">typing</code> module to declare that this function returns an iterator of integers. This is the correct annotation for a generator function — it signals to type checkers (and human readers) that the return value is not a list but something to be consumed lazily. In Python 3.9+, <code class="language-plaintext highlighter-rouge">Iterator</code> can be imported directly from <code class="language-plaintext highlighter-rouge">collections.abc</code> instead.</p>

<h2 id="putting-it-together">Putting It Together</h2>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">answer</span><span class="p">(</span><span class="n">number</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
    <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="n">prime_factors</span><span class="p">(</span><span class="n">number</span><span class="p">))[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">prime_factors</code> yields factors in ascending order because <code class="language-plaintext highlighter-rouge">smallest_divisor</code> always returns the <em>smallest</em> factor first. Collecting them into a list and taking the last element <code class="language-plaintext highlighter-rouge">[-1]</code> gives the largest prime factor directly.</p>

<p>For <code class="language-plaintext highlighter-rouge">600_851_475_143</code>, the full factorisation is <code class="language-plaintext highlighter-rouge">71 × 839 × 1471 × 6857</code>, so the answer is the final element: <strong>6857</strong>.</p>

<p><strong>Answer: 6857</strong></p>]]></content><author><name>Daniel Birmajer</name></author><category term="Blog" /><category term="Project Euler" /><category term="python" /><category term="primes" /><category term="factorisation" /><category term="recursion" /><category term="generators" /><category term="type hints" /><summary type="html"><![CDATA[The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143?]]></summary></entry><entry><title type="html">Project Euler #001: Multiples of 3 or 5</title><link href="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/project%20euler/post-link-euler-001/" rel="alternate" type="text/html" title="Project Euler #001: Multiples of 3 or 5" /><published>2026-03-27T00:00:00+00:00</published><updated>2026-03-27T00:00:00+00:00</updated><id>https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/project%20euler/post-link%20euler-001</id><content type="html" xml:base="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/project%20euler/post-link-euler-001/"><![CDATA[<blockquote>
  <p>If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.</p>
</blockquote>

<h2 id="the-mathematics">The Mathematics</h2>

<p>We want every integer <code class="language-plaintext highlighter-rouge">x</code> in the range <code class="language-plaintext highlighter-rouge">[1, 999]</code> such that <code class="language-plaintext highlighter-rouge">3 | x</code> or <code class="language-plaintext highlighter-rouge">5 | x</code> (read: “3 divides x” or “5 divides x”).</p>

<p>The elegant closed-form approach uses the <strong>inclusion–exclusion principle</strong>. Define <code class="language-plaintext highlighter-rouge">S(k, n)</code> as the sum of all multiples of <code class="language-plaintext highlighter-rouge">k</code> strictly below <code class="language-plaintext highlighter-rouge">n</code>. Since these form an arithmetic series <code class="language-plaintext highlighter-rouge">k, 2k, 3k, …</code> with <code class="language-plaintext highlighter-rouge">p = ⌊(n−1)/k⌋</code> terms:</p>

<h2 id="the-sage-solution">The Sage Solution</h2>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="c1"># S(k, n) = k · p · (p + 1) / 2
</span>
<span class="k">def</span> <span class="nf">S</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">n</span><span class="p">):</span>
    <span class="n">p</span> <span class="o">=</span> <span class="p">(</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">//</span> <span class="n">k</span>
    <span class="k">return</span> <span class="n">k</span> <span class="o">*</span> <span class="n">p</span> <span class="o">*</span> <span class="p">(</span><span class="n">p</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span>

<span class="n">S</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1_000</span><span class="p">)</span> <span class="o">+</span> <span class="n">S</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">1_000</span><span class="p">)</span> <span class="o">-</span> <span class="n">S</span><span class="p">(</span><span class="mi">15</span><span class="p">,</span> <span class="mi">1_000</span><span class="p">)</span>

<span class="o">&gt;</span> <span class="mi">233168</span>
</code></pre></div></div>
<p>The answer is then <code class="language-plaintext highlighter-rouge">S(3, 1,000) + S(5, 1,000) − S(15, 1,000)</code> — we subtract multiples of 15 because they were counted twice (once as multiples of 3, once as multiples of 5). This runs in <strong>O(1)</strong> time regardless of <code class="language-plaintext highlighter-rouge">n</code>.</p>

<h2 id="the-python-solution">The Python Solution</h2>

<p>The one-liner below takes a more direct, Pythonic approach using a generator expression inside <code class="language-plaintext highlighter-rouge">sum()</code>:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">answer</span><span class="p">(</span><span class="n">n</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
  <span class="k">return</span> <span class="nb">sum</span><span class="p">(</span>
      <span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> 
      <span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">%</span> <span class="mi">3</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">x</span> <span class="o">%</span> <span class="mi">5</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span>
      <span class="p">)</span>
 
<span class="c1"># "below 1_000" means range(1_000)
</span><span class="k">print</span><span class="p">(</span><span class="n">answer</span><span class="p">(</span><span class="mi">1_000</span><span class="p">))</span>  <span class="c1"># 233168
</span></code></pre></div></div>

<h2 id="why-the-trick-works">Why the Trick Works</h2>

<p>The condition <code class="language-plaintext highlighter-rouge">(x % 3) * (x % 5) == 0</code> exploits the <strong>zero-product property</strong>: a product of integers is zero if and only if at least one factor is zero. So the expression is <code class="language-plaintext highlighter-rouge">True</code> whenever <code class="language-plaintext highlighter-rouge">x % 3 == 0</code> <em>or</em> <code class="language-plaintext highlighter-rouge">x % 5 == 0</code> — exactly our condition — without needing the <code class="language-plaintext highlighter-rouge">or</code> keyword.</p>

<p>Compared to the O(1) formula this is <strong>O(n)</strong>, but for <code class="language-plaintext highlighter-rouge">n = 1,000</code> the difference is imperceptible. Python’s generator expression also avoids materialising a list in memory; it streams values one by one into <code class="language-plaintext highlighter-rouge">sum()</code>.</p>

<p><strong>Answer (n = 1000): 233168</strong></p>]]></content><author><name>Daniel Birmajer</name></author><category term="Blog" /><category term="Project Euler" /><category term="python" /><category term="arithmetic" /><category term="divisibility" /><category term="generators" /><summary type="html"><![CDATA[If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.]]></summary></entry><entry><title type="html">Project Euler #002: Even Fibonacci Numbers</title><link href="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/project%20euler/post-link-euler-002/" rel="alternate" type="text/html" title="Project Euler #002: Even Fibonacci Numbers" /><published>2026-03-27T00:00:00+00:00</published><updated>2026-03-27T00:00:00+00:00</updated><id>https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/project%20euler/post-link%20euler-002</id><content type="html" xml:base="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/project%20euler/post-link-euler-002/"><![CDATA[<blockquote>
  <p>Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, … By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.</p>
</blockquote>

<h2 id="the-mathematics">The Mathematics</h2>

<p>The Fibonacci sequence is defined by the recurrence $F(n) = F(n−1) + F(n−2)$ with seeds $F(0) = 0, F(1) = 1$.</p>

<p>A beautiful observation: <strong>every third Fibonacci number is even</strong>. This follows from the parity pattern of the sequence — <code class="language-plaintext highlighter-rouge">even, odd, odd, even, odd, odd, even, …</code> — which repeats with period 3. So rather than checking each term for evenness, we could jump three steps at a time using the identity $F(n+3) = 4·F(n) + F(n−3)$. Our solution below takes the simpler filtering approach, which is perfectly readable and fast enough for this limit.</p>

<h2 id="the-python-solution">The Python Solution</h2>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Iterator</span>
<span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">takewhile</span>

<span class="k">def</span> <span class="nf">fibonacci</span><span class="p">(</span><span class="n">a</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">b</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">1</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Iterator</span><span class="p">[</span><span class="nb">int</span><span class="p">]:</span>
    <span class="s">"""
    Generate an infinite Fibonacci sequence.

    This function returns a generator that yields Fibonacci numbers indefinitely,
    starting from the given initial values a and b.

    Parameters
    ----------
    a : int, optional
        The first number in the sequence, by default 0
    b : int, optional
        The second number in the sequence, by default 1

    Yields
    ------
    Iterator[int]
        An infinite generator of Fibonacci numbers.

    Examples
    --------
    &gt;&gt;&gt; gen = fibonacci()
    &gt;&gt;&gt; next(gen)
    0
    &gt;&gt;&gt; next(gen)
    1
    &gt;&gt;&gt; next(gen)
    1
    &gt;&gt;&gt; next(gen)
    2
    """</span>
    <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
        <span class="k">yield</span> <span class="n">a</span>
        <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">b</span><span class="p">,</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span>


<span class="k">def</span> <span class="nf">answer</span><span class="p">(</span><span class="n">limit</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span><span class="p">:</span>
    <span class="s">"""
    Return the sum of even-valued Fibonacci numbers not exceeding n.

    This function solves Project Euler problem 2 by generating Fibonacci numbers
    and summing only the even-valued ones that are less than or equal to 4,000,000.

    Returns
    -------
    int
        The sum of even Fibonacci numbers not exceeding 4 million.

    Examples
    --------
    &gt;&gt;&gt; answer(4_000_000)
    4613732
    """</span>
    <span class="k">return</span> <span class="nb">sum</span><span class="p">(</span>
        <span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">takewhile</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span> <span class="o">&lt;=</span> <span class="n">limit</span><span class="p">,</span> <span class="n">fibonacci</span><span class="p">())</span>
        <span class="k">if</span> <span class="n">x</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span>
        <span class="p">)</span>

<span class="k">print</span><span class="p">(</span><span class="n">answer</span><span class="p">(</span><span class="mi">4_000_000</span><span class="p">))</span>  <span class="c1"># 4613732
</span></code></pre></div></div>

<h2 id="generator-functions-in-python">Generator Functions in Python</h2>

<p>The <code class="language-plaintext highlighter-rouge">yield</code> keyword transforms <code class="language-plaintext highlighter-rouge">fibonacci</code> into a <strong>generator function</strong>. Instead of computing the entire sequence and returning a list, it produces one value at a time — resuming where it left off each time the caller asks for the next item. Memory usage is <strong>O(1)</strong> regardless of how large <code class="language-plaintext highlighter-rouge">limit</code> gets.</p>

<p>The tuple-swap <code class="language-plaintext highlighter-rouge">a, b = b, a + b</code> is idiomatic Python: the right-hand side is fully evaluated before any assignment occurs, so no temporary variable is needed — the Fibonacci step is atomic.</p>

<p><strong>Answer (limit = 4,000,000): 4613732</strong></p>]]></content><author><name>Daniel Birmajer</name></author><category term="Blog" /><category term="Project Euler" /><category term="python" /><category term="fibonacci" /><category term="generators" /><category term="number theory" /><summary type="html"><![CDATA[Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, … By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.]]></summary></entry><entry><title type="html">LaTeX support</title><link href="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/math-examples/" rel="alternate" type="text/html" title="LaTeX support" /><published>2024-02-29T00:00:00+00:00</published><updated>2024-02-29T00:00:00+00:00</updated><id>https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/math-examples</id><content type="html" xml:base="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/math-examples/"><![CDATA[<p>Inline: $x^2$ or \(\frac{y}{z}\).</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Inline: $x^2$ or \\(\frac{y}{z}\\).
</code></pre></div></div>

<p>Display: \[\frac{y}{z}\]</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Display: \\[\frac{y}{z}\\]
</code></pre></div></div>]]></content><author><name>Daniel Birmajer</name></author><category term="blog" /><category term="Jekyll" /><category term="math" /><summary type="html"><![CDATA[Inline: $x^2$ or \(\frac{y}{z}\).]]></summary></entry><entry><title type="html">Welcome to Jekyll!</title><link href="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/welcome-to-jekyll/" rel="alternate" type="text/html" title="Welcome to Jekyll!" /><published>2019-04-18T19:34:30+00:00</published><updated>2019-04-18T19:34:30+00:00</updated><id>https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/welcome-to-jekyll</id><content type="html" xml:base="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/welcome-to-jekyll/"><![CDATA[<p>You’ll find this post in your <code class="language-plaintext highlighter-rouge">_posts</code> directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run <code class="language-plaintext highlighter-rouge">jekyll serve</code>, which launches a web server and auto-regenerates your site when a file is updated.</p>

<p>To add new posts, simply add a file in the <code class="language-plaintext highlighter-rouge">_posts</code> directory that follows the convention <code class="language-plaintext highlighter-rouge">YYYY-MM-DD-name-of-post.ext</code> and includes the necessary front matter. Take a look at the source for this post to get an idea about how it works.</p>

<p>Jekyll also offers powerful support for code snippets:</p>

<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">print_hi</span><span class="p">(</span><span class="nb">name</span><span class="p">)</span>
  <span class="nb">puts</span> <span class="s2">"Hi, </span><span class="si">#{</span><span class="nb">name</span><span class="si">}</span><span class="s2">"</span>
<span class="k">end</span>
<span class="n">print_hi</span><span class="p">(</span><span class="s1">'Tom'</span><span class="p">)</span>
<span class="c1">#=&gt; prints 'Hi, Tom' to STDOUT.</span>
</code></pre></div></div>

<p>Check out the <a href="https://jekyllrb.com/docs/home">Jekyll docs</a> for more info on how to get the most out of Jekyll. File all bugs/feature requests at <a href="https://github.com/jekyll/jekyll">Jekyll’s GitHub repo</a>. If you have questions, you can ask them on <a href="https://talk.jekyllrb.com/">Jekyll Talk</a>.</p>]]></content><author><name>Daniel Birmajer</name></author><category term="blog" /><category term="Jekyll" /><category term="update" /><summary type="html"><![CDATA[You’ll find this post in your _posts directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run jekyll serve, which launches a web server and auto-regenerates your site when a file is updated.]]></summary></entry><entry><title type="html">Post: Link</title><link href="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-link/" rel="alternate" type="text/html" title="Post: Link" /><published>2010-03-07T00:00:00+00:00</published><updated>2010-03-07T00:00:00+00:00</updated><id>https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-link</id><content type="html" xml:base="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-link/"><![CDATA[<p>This theme supports <strong>link posts</strong>, made famous by John Gruber. To use, just add <code class="language-plaintext highlighter-rouge">link: http://url-you-want-linked</code> to the post’s YAML front matter and you’re done.</p>

<blockquote>
  <p>And this is how a quote looks.</p>
</blockquote>

<p>Some <a href="#">link</a> can also be shown.</p>]]></content><author><name>Daniel Birmajer</name></author><category term="Blog" /><category term="link" /><category term="Post Formats" /><summary type="html"><![CDATA[This theme supports link posts, made famous by John Gruber. To use, just add link: http://url-you-want-linked to the post’s YAML front matter and you’re done.]]></summary></entry><entry><title type="html">Post: Notice</title><link href="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-notice/" rel="alternate" type="text/html" title="Post: Notice" /><published>2010-02-05T00:00:00+00:00</published><updated>2010-02-05T00:00:00+00:00</updated><id>https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-notice</id><content type="html" xml:base="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-notice/"><![CDATA[<p>A notice displays information that explains nearby content. Often used to call attention to a particular detail.</p>

<p>When using Kramdown <code class="language-plaintext highlighter-rouge">{: .notice}</code> can be added after a sentence to assign the <code class="language-plaintext highlighter-rouge">.notice</code> to the <code class="language-plaintext highlighter-rouge">&lt;p&gt;&lt;/p&gt;</code> element.</p>

<p class="notice"><strong>Changes in Service:</strong> We just updated our <a href="#">privacy policy</a> here to better service our customers. We recommend reviewing the changes.</p>

<p class="notice--primary"><strong>Primary Notice:</strong> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. <a href="#">Praesent libero</a>. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet.</p>

<p class="notice--info"><strong>Info Notice:</strong> Lorem ipsum dolor sit amet, <a href="#">consectetur adipiscing elit</a>. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet.</p>

<p class="notice--warning"><strong>Warning Notice:</strong> Lorem ipsum dolor sit amet, consectetur adipiscing elit. <a href="#">Integer nec odio</a>. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet.</p>

<p class="notice--danger"><strong>Danger Notice:</strong> Lorem ipsum dolor sit amet, <a href="#">consectetur adipiscing</a> elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet.</p>

<p class="notice--success"><strong>Success Notice:</strong> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at <a href="#">nibh elementum</a> imperdiet.</p>

<p>Want to wrap several paragraphs or other elements in a notice? Using Liquid to capture the content and then filter it with <code class="language-plaintext highlighter-rouge">markdownify</code> is a good way to go.</p>

<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code>{% capture notice-2 %}
#### New Site Features

* You can now have cover images on blog pages
* Drafts will now auto-save while writing
{% endcapture %}

<span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"notice"</span><span class="nt">&gt;</span>{{ notice-2 | markdownify }}<span class="nt">&lt;/div&gt;</span>
</code></pre></div></div>

<div class="notice">
  
<h4 id="new-site-features">New Site Features</h4>

<ul>
  <li>You can now have cover images on blog pages</li>
  <li>Drafts will now auto-save while writing</li>
</ul>

</div>

<p>Or you could skip the capture and stick with straight HTML.</p>

<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"notice"</span><span class="nt">&gt;</span>
  <span class="nt">&lt;h4&gt;</span>Message<span class="nt">&lt;/h4&gt;</span>
  <span class="nt">&lt;p&gt;</span>A basic message.<span class="nt">&lt;/p&gt;</span>
<span class="nt">&lt;/div&gt;</span>
</code></pre></div></div>

<div class="notice">
  <h4>Message</h4>
  <p>A basic message.</p>
</div>]]></content><author><name>Daniel Birmajer</name></author><category term="Blog" /><category term="Post Formats" /><category term="notice" /><summary type="html"><![CDATA[A notice displays information that explains nearby content. Often used to call attention to a particular detail.]]></summary></entry><entry><title type="html">Post: Quote</title><link href="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-quote/" rel="alternate" type="text/html" title="Post: Quote" /><published>2010-02-05T00:00:00+00:00</published><updated>2010-02-05T00:00:00+00:00</updated><id>https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-quote</id><content type="html" xml:base="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-quote/"><![CDATA[<blockquote>
  <p>Only one thing is impossible for God: To find any sense in any copyright law on the planet.</p>
</blockquote>

<blockquote>
  <p><cite><a href="http://www.brainyquote.com/quotes/quotes/m/marktwain163473.html">Mark Twain</a></cite></p>
</blockquote>]]></content><author><name>Daniel Birmajer</name></author><category term="Blog" /><category term="Post Formats" /><category term="quote" /><summary type="html"><![CDATA[Only one thing is impossible for God: To find any sense in any copyright law on the planet. Mark Twain]]></summary></entry><entry><title type="html">Post: Chat</title><link href="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-chat/" rel="alternate" type="text/html" title="Post: Chat" /><published>2010-01-08T00:00:00+00:00</published><updated>2010-01-08T00:00:00+00:00</updated><id>https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-chat</id><content type="html" xml:base="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-chat/"><![CDATA[<p>Abbott: Strange as it may seem, they give ball players nowadays very peculiar names.</p>

<p>Costello: Funny names?</p>

<p>Abbott: Nicknames, nicknames. Now, on the St. Louis team we have Who’s on first, What’s on second, I Don’t Know is on third–</p>

<p>Costello: That’s what I want to find out. I want you to tell me the names of the fellows on the St. Louis team.</p>

<p>Abbott: I’m telling you. Who’s on first, What’s on second, I Don’t Know is on third–</p>

<p>Costello: You know the fellows’ names?</p>

<p>Abbott: Yes.</p>

<p>Costello: Well, then who’s playing first?</p>

<p>Abbott: Yes.</p>

<p>Costello: I mean the fellow’s name on first base.</p>

<p>Abbott: Who.</p>

<p>Costello: The fellow playin’ first base.</p>

<p>Abbott: Who.</p>

<p>Costello: The guy on first base.</p>

<p>Abbott: Who is on first.</p>

<p>Costello: Well, what are you askin’ me for?</p>

<p>Abbott: I’m not asking you–I’m telling you. Who is on first.</p>

<p>Costello: I’m asking you–who’s on first?</p>

<p>Abbott: That’s the man’s name.</p>

<p>Costello: That’s who’s name?</p>

<p>Abbott: Yes.</p>

<p>Costello: When you pay off the first baseman every month, who gets the money?</p>

<p>Abbott: Every dollar of it. And why not, the man’s entitled to it.</p>

<p>Costello: Who is?</p>

<p>Abbott: Yes.</p>

<p>Costello: So who gets it?</p>

<p>Abbott: Why shouldn’t he? Sometimes his wife comes down and collects it.</p>

<p>Costello: Who’s wife?</p>

<p>Abbott: Yes. After all, the man earns it.</p>

<p>Costello: Who does?</p>

<p>Abbott: Absolutely.</p>

<p>Costello: Well, all I’m trying to find out is what’s the guy’s name on first base?</p>

<p>Abbott: Oh, no, no. What is on second base.</p>

<p>Costello: I’m not asking you who’s on second.</p>

<p>Abbott: Who’s on first!</p>

<p>Costello: St. Louis has a good outfield?</p>

<p>Abbott: Oh, absolutely.</p>

<p>Costello: The left fielder’s name?</p>

<p>Abbott: Why.</p>

<p>Costello: I don’t know, I just thought I’d ask.</p>

<p>Abbott: Well, I just thought I’d tell you.</p>

<p>Costello: Then tell me who’s playing left field?</p>

<p>Abbott: Who’s playing first.</p>

<p>Costello: Stay out of the infield! The left fielder’s name?</p>

<p>Abbott: Why.</p>

<p>Costello: Because.</p>

<p>Abbott: Oh, he’s center field.</p>

<p>Costello: Wait a minute. You got a pitcher on this team?</p>

<p>Abbott: Wouldn’t this be a fine team without a pitcher?</p>

<p>Costello: Tell me the pitcher’s name.</p>

<p>Abbott: Tomorrow.</p>

<p>Costello: Now, when the guy at bat bunts the ball–me being a good catcher–I want to throw the guy out at first base, so I pick up the ball and throw it to who?</p>

<p>Abbott: Now, that’s he first thing you’ve said right.</p>

<p>Costello: I DON’T EVEN KNOW WHAT I’M TALKING ABOUT!</p>

<p>Abbott: Don’t get excited. Take it easy.</p>

<p>Costello: I throw the ball to first base, whoever it is grabs the ball, so the guy runs to second. Who picks up the ball and throws it to what. What throws it to I don’t know. I don’t know throws it back to tomorrow–a triple play.</p>

<p>Abbott: Yeah, it could be.</p>

<p>Costello: Another guy gets up and it’s a long ball to center.</p>

<p>Abbott: Because.</p>

<p>Costello: Why? I don’t know. And I don’t care.</p>

<p>Abbott: What was that?</p>

<p>Costello: I said, I DON’T CARE!</p>

<p>Abbott: Oh, that’s our shortstop!</p>]]></content><author><name>Daniel Birmajer</name></author><category term="Blog" /><category term="chat" /><category term="Post Formats" /><summary type="html"><![CDATA[Abbott: Strange as it may seem, they give ball players nowadays very peculiar names.]]></summary></entry><entry><title type="html">Post: Modified Date</title><link href="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-modified/" rel="alternate" type="text/html" title="Post: Modified Date" /><published>2010-01-07T00:00:00+00:00</published><updated>2016-03-09T21:20:02+00:00</updated><id>https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-modified</id><content type="html" xml:base="https://abirmaj6-naz.github.io/PROTEUS-Pages/blog/post-modified/"><![CDATA[<p>This post has been updated and should show a modified date if used in a layout.</p>

<p>All children, except one, grow up. They soon know that they will grow up, and the way Wendy knew was this. One day when she was two years old she was playing in a garden, and she plucked another flower and ran with it to her mother. I suppose she must have looked rather delightful, for Mrs. Darling put her hand to her heart and cried, “Oh, why can’t you remain like this for ever!” This was all that passed between them on the subject, but henceforth Wendy knew that she must grow up. You always know after you are two. Two is the beginning of the end.</p>]]></content><author><name>Daniel Birmajer</name></author><category term="Blog" /><category term="Post Formats" /><category term="readability" /><category term="standard" /><summary type="html"><![CDATA[This post has been updated and should show a modified date if used in a layout.]]></summary></entry></feed>