feat(post): collapse entries

This commit is contained in:
Barrett Ruth 2024-06-17 19:47:59 -05:00
parent b406a073c9
commit 409089b1d4
4 changed files with 115 additions and 77 deletions

View file

@ -42,6 +42,7 @@
</header> </header>
<article class="post-article"> <article class="post-article">
<h2>technique overview</h2> <h2>technique overview</h2>
<div class="problem-header">
<h3> <h3>
<a <a
target="blank" target="blank"
@ -49,6 +50,8 @@
>container with most water</a >container with most water</a
> >
</h3> </h3>
</div>
<div class="problem-content">
<p>Sometimes, the mathematical solution is the simplest.</p> <p>Sometimes, the mathematical solution is the simplest.</p>
<p> <p>
The area of a container bounded by the ground and its columns at The area of a container bounded by the ground and its columns at
@ -56,13 +59,14 @@
\text{length} = (r - l) \cdot \min\{height[l], height[r]\} \] \text{length} = (r - l) \cdot \min\{height[l], height[r]\} \]
</p> </p>
<p> <p>
At its core, this is a maximization problem: maximize the contained At its core, this is a maximization problem: maximize the
area. \[ \max\{(r - l) \cdot \min\{height[l], height[r]\}\} \] contained area. \[ \max\{(r - l) \cdot \min\{height[l],
height[r]\}\} \]
</p> </p>
<p> <p>
Given a new column position \(l_0 < l\) or \(r_0 < r\), the Given a new column position \(l_0 < l\) or \(r_0 < r\), the
contained area can only increase if the height of the corresponding contained area can only increase if the height of the
column increases. corresponding column increases.
</p> </p>
<!-- TODO: add footnote --> <!-- TODO: add footnote -->
<p> <p>
@ -72,7 +76,7 @@
maintained. maintained.
</p> </p>
<div class="post-code"> <div class="post-code">
<pre><code class="language-python">def maxArea(height: list[int]) -> int: <pre><code class="language-python">`def maxArea(height: list[int]) -> int:
ans = 0 ans = 0
l, r = 0, len(height) - 1 l, r = 0, len(height) - 1
@ -85,8 +89,10 @@
while l < r and height[r] <= min_height: while l < r and height[r] <= min_height:
r -= 1 r -= 1
return ans</code></pre> return ans`</code></pre>
</div> </div>
</div>
<div class="problem-header">
<h3> <h3>
<a <a
target="blank" target="blank"
@ -94,6 +100,8 @@
>boats to save people</a >boats to save people</a
> >
</h3> </h3>
</div>
<div class="problem-content">
<p> <p>
Usually, the metaphorical problem description is a distraction. Usually, the metaphorical problem description is a distraction.
However, I find that thinking within the confines of "boats" and However, I find that thinking within the confines of "boats" and
@ -102,15 +110,17 @@
<p> <p>
<!-- TODO: footnote --> <!-- TODO: footnote -->
Since only two people can fit in a boat at a time, pairing up Since only two people can fit in a boat at a time, pairing up
lightest and heaviest individuals will result in the least amount of lightest and heaviest individuals will result in the least amount
boats being used. of boats being used.
</p> </p>
<p> <p>
However, the weights are given in random order. Efficiently pairing However, the weights are given in random order. Efficiently
up the lightest and heaviest individuals, then, requires the most pairing up the lightest and heaviest individuals, then, requires
common two-pointers prepreocessing step: sorting. the most common two-pointers prepreocessing step: sorting.
</p>
<p>
Finally, flesh out any remaining aspects of the implementation:
</p> </p>
<p>Finally, flesh out any remaining aspects of the implementation:</p>
<ol> <ol>
<li>If one person remains, give them a boat.</li> <li>If one person remains, give them a boat.</li>
<li> <li>
@ -139,6 +149,7 @@
return ans</code></pre> return ans</code></pre>
</div> </div>
</div>
</article> </article>
</div> </div>
</main> </main>

View file

@ -5,3 +5,4 @@ My portfolio website
## todo ## todo
- Mobile support - Mobile support
- Problem toggler

View file

@ -1,3 +1,4 @@
document.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll("article h2").forEach((h2) => { document.querySelectorAll("article h2").forEach((h2) => {
const mdHeading = document.createElement("span"); const mdHeading = document.createElement("span");
mdHeading.textContent = "# "; mdHeading.textContent = "# ";
@ -5,9 +6,21 @@ document.querySelectorAll("article h2").forEach((h2) => {
h2.prepend(mdHeading); h2.prepend(mdHeading);
}); });
document.querySelectorAll("article h3").forEach((h3) => { document.querySelectorAll(".problem-header h3").forEach((h3) => {
const toggle = document.createElement("span");
toggle.textContent = "v";
toggle.classList.add("problem-toggle");
toggle.addEventListener("click", () => {
const content = h3.parentElement.nextElementSibling;
content.style.display = toggle.textContent === ">" ? "block" : "none";
toggle.textContent = toggle.textContent === ">" ? "v" : ">";
});
const mdHeading = document.createElement("span"); const mdHeading = document.createElement("span");
mdHeading.textContent = "## "; mdHeading.textContent = "## ";
mdHeading.style.color = "#0073e6"; mdHeading.style.color = "#0073e6";
h3.prepend(mdHeading); h3.prepend(mdHeading);
h3.prepend(toggle);
});
}); });

View file

@ -85,6 +85,19 @@ header {
display: flex; display: flex;
justify-content: center; justify-content: center;
} }
.language-python { .language-python {
font-size: 0.9em !important; /* override prism.js styles */
font-size: 0.85em !important;
}
.problem-header {
position: relative;
}
.problem-toggle {
font-family: "Courier New", monospace;
position: absolute;
cursor: pointer;
left: -25px;
} }