<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Sumit Mishra]]></title><description><![CDATA[Mathematics, algorithms, and intelligent systems by Sumit Mishra (ossm). Exploring competitive programming, reinforcement learning, and practical insights.]]></description><link>https://ossm.me</link><image><url>https://cdn.hashnode.com/uploads/logos/69dce08d900c6a0f145ca395/fb5b65ae-8caa-49e6-bec1-f3a6a3cc151f.png</url><title>Sumit Mishra</title><link>https://ossm.me</link></image><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 12:07:23 GMT</lastBuildDate><atom:link href="https://ossm.me/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The Protein Whisperer]]></title><description><![CDATA[Dr. Maya Chen had spent fifteen years staring at the same problem, and it stared back at her the way all great problems do — with patience, and without mercy. She worked in a mid-sized university labo]]></description><link>https://ossm.me/the-protein-whisperer</link><guid isPermaLink="true">https://ossm.me/the-protein-whisperer</guid><dc:creator><![CDATA[Sumit Mishra]]></dc:creator><pubDate>Sun, 19 Apr 2026 09:58:10 GMT</pubDate><content:encoded><![CDATA[<p>Dr. Maya Chen had spent fifteen years staring at the same problem, and it stared back at her the way all great problems do — with patience, and without mercy. She worked in a mid-sized university laboratory that smelled permanently of ethanol and cold coffee, surrounded by centrifuges that hummed like anxious monks and whiteboards covered in the accumulated frustration of many failed hypotheses. Her subject of study was proteins, and proteins, as she had come to understand them, were among the most maddeningly beautiful things in existence.</p>
<p>Every living creature ran on proteins. The enzymes that broke down food in your stomach, the hemoglobin carrying oxygen through your arteries, the antibodies patrolling your bloodstream for invaders — all of them proteins, all of them doing their work with a specificity and elegance that no human engineer had ever matched. But proteins kept their secrets jealously. They performed their functions not merely because of what they were made of, but because of the shape they assumed, and that shape was extraordinarily difficult to know.</p>
<p>Ravi, her graduate student, had arrived from Hyderabad with a sharp mind and an endearing habit of asking the questions that everyone else considered too basic to voice. On a grey Tuesday afternoon, while rain tapped steadily at the laboratory windows, he sat across from her and asked one of those questions. She had been explaining the problem of protein folding, and he had listened carefully, and then he said that it sounded impossible. She told him that it had been, for about fifty years.</p>
<p>To understand why, one had to begin with the alphabet. Proteins were built from amino acids, a set of twenty molecular building blocks, strung together in sequences that could run to tens of thousands of units in length. A gene was essentially an instruction: assemble these amino acids, in this order. But the resulting chain did not remain a chain. It folded. Guided by forces that operated at the atomic scale — hydrogen bonds drawing certain atoms toward each other, hydrophobic regions fleeing from water, electrical charges attracting and repelling across infinitesimal distances — the protein collapsed into a precise three-dimensional shape. That shape was not decorative. It was functional. The contours and cavities of a folded protein determined whether it would act as a catalyst, a carrier, a signal, a structural support, or a lock awaiting the right molecular key. When the folding went wrong, as it did in diseases like Alzheimer's and Parkinson's, the consequences spread through the body with slow catastrophe.</p>
<p>The only reliable way to observe a protein's shape, for most of the twentieth century, was a technique called X-ray crystallography, in which researchers coaxed proteins into forming crystals and then bombarded those crystals with X-ray beams, interpreting the resulting diffraction patterns to reconstruct the molecular architecture. It was painstaking work. A single structure could demand years of effort and sometimes could not be resolved at all. The known universe of proteins numbered in the hundreds of millions. The library of mapped structures, after decades of global scientific effort, contained perhaps two hundred thousand. The distance between what existed and what was known was, in practical terms, almost incomprehensible.</p>
<p>Maya walked to the whiteboard when she reached this part of the explanation, as she always did when ideas required space. She drew two parallel lines representing protein chains and spoke about evolution, which was, she said, simply the longest experiment the planet had ever conducted. Over billions of years of mutation and selection, proteins had been tested relentlessly. When an amino acid in a functional protein changed, the protein frequently broke, and the organism that depended on it died. But sometimes, when one amino acid changed, another changed alongside it, somewhere else in the chain, compensating, preserving the fold, maintaining the shape that kept the creature alive. These correlated mutations, tracked across thousands of species and millions of years, carried a hidden message. Amino acids that changed together across evolutionary time were, almost invariably, close neighbors in three-dimensional space. They were the protein's autobiography, written in the language of survival, and AlphaFold had learned to read it.</p>
<p>The first versions of AlphaFold, developed by a team at DeepMind, demonstrated that a machine learning system trained on the evolutionary record of protein sequences could predict folded structures with an accuracy that stunned the scientific community. The third iteration extended the ambition considerably. Proteins, it turned out, rarely acted in isolation. They bound to strands of DNA, latched onto RNA molecules, docked with small chemical compounds, and clasped the surfaces of other proteins in interactions whose geometry was as important as any individual structure. AlphaFold 3 was trained to model these interactions, to predict not merely the shape of a protein in solitude but the shape it assumed in relationship, the configuration it adopted when it was, as Maya put it to Ravi, moving through a room and deciding who to embrace.</p>
<p>The training data was the accumulated structural knowledge of biology — every crystal structure, every cryo-electron microscopy image, every nuclear magnetic resonance map that the scientific community had produced across decades of effort — digested by a system capable of finding patterns at a depth no human analyst could reach. The network did not memorize. It generalized. It extracted from the data something resembling an understanding of the underlying physical grammar of molecular shape, and it applied that understanding to sequences it had never encountered.</p>
<p>The practical consequences arrived quickly. Structures that had resisted experimental determination for years were predicted in minutes. Researchers working on neglected tropical diseases, on antibiotic-resistant bacteria, on cancers that had proven stubbornly unresponsive to existing treatments, found themselves suddenly able to examine the shapes of proteins that had previously been inaccessible. Drug designers could identify binding pockets — the molecular hollows and clefts where a carefully shaped compound might lodge itself and alter a protein's behavior. A laboratory in Seoul reported progress on a rare childhood disease. A researcher working in Kenya mapped a parasite protein that had never been structurally characterized. The tool was made publicly available, and people used it everywhere, from graduate seminars to high school science competitions.</p>
<p>Ravi asked, at the end of one of these conversations, whether AlphaFold 3 was simply correct, whether the problem had been solved and the remaining work was merely application. Maya gave him the kind of look that good scientists reserve for questions that contain comfortable assumptions. The system struggled with disordered proteins, she explained — molecules that did not hold a fixed shape but instead existed in a perpetual fluid motion, adopting different conformations in different contexts. It occasionally missed rare structural states. Its predictions, however accurate, remained predictions, models of what a protein probably looked like rather than direct observations of what it demonstrably was. Experimental confirmation still mattered. The picture was clearer, not complete.</p>
<p>But the nature of the problem had shifted, and that was perhaps the most significant thing. For half a century the central question had been whether the shape of a protein could be found at all, whether the gap between sequence and structure could be crossed. That question had changed. The new question was what to do with structures once they were known, how to interpret the shapes, how to use them to design molecules that might intervene in disease, how to understand the dynamic interactions between proteins and the environments they inhabited. It was, as Maya had observed, a considerably better problem to be working on. She turned away from the whiteboard and looked at the rain still falling outside, and felt, as she sometimes did in moments of genuine scientific progress, the specific satisfaction of a door that had stood closed for a very long time finally swinging open onto something worth seeing.</p>
]]></content:encoded></item><item><title><![CDATA[Applied Mathematics in Machine Learning]]></title><description><![CDATA[Machine learning is fundamentally an application of mathematics—especially linear algebra, probability theory, and optimization.
In this article, we derive key concepts from first principles.
1. Probl]]></description><link>https://ossm.me/applied-mathematics-in-machine-learning</link><guid isPermaLink="true">https://ossm.me/applied-mathematics-in-machine-learning</guid><dc:creator><![CDATA[Sumit Mishra]]></dc:creator><pubDate>Sun, 19 Apr 2026 01:59:38 GMT</pubDate><content:encoded><![CDATA[<p>Machine learning is fundamentally an application of mathematics—especially linear algebra, probability theory, and optimization.</p>
<p>In this article, we derive key concepts from first principles.</p>
<h2>1. Problem Setup</h2>
<p>We define a supervised learning dataset:</p>
<p>$$
\mathcal{D} = {(x^{(i)}, y^{(i)})}_{i=1}^{m}
$$</p>
<p>where:</p>
<p>$$
x^{(i)} \in \mathbb{R}^n
$$</p>
<p>$$
y^{(i)} \in \mathbb{R}
$$</p>
<p>We want to learn a function:</p>
<p>$$
h_\theta : \mathbb{R}^n \rightarrow \mathbb{R}
$$</p>
<hr />
<h2>2. Linear Model</h2>
<p>We define:</p>
<p>$$
h_\theta(x) = \theta^T x + b
$$</p>
<p>Expanded:</p>
<p>$$
h_\theta(x) = \sum_{j=1}^{n} \theta_j x_j + b
$$</p>
<hr />
<h2>3. Loss Function</h2>
<p>Mean Squared Error:</p>
<p>$$
J(\theta) = \frac{1}{m} \sum_{i=1}^{m} \left( h_\theta(x^{(i)}) - y^{(i)} \right)^2
$$</p>
<hr />
<h2>4. Optimization Objective</h2>
<p>We solve:</p>
<p>$$
\theta^* = \arg\min_\theta J(\theta)
$$</p>
<hr />
<h2>5. Gradient Descent</h2>
<p>Gradient:</p>
<p>$$
\frac{\partial J}{\partial \theta} = \frac{2}{m} \sum_{i=1}^{m} x^{(i)} \left( \theta^T x^{(i)} - y^{(i)} \right)
$$</p>
<p>Update rule:</p>
<p>$$
\theta := \theta - \alpha \nabla_\theta J(\theta)
$$</p>
<hr />
<h2>6. Vectorized Form</h2>
<p>$$
J(\theta) = \frac{1}{m} (X\theta - y)^T (X\theta - y)
$$</p>
<p>Gradient:</p>
<p>$$
\nabla_\theta J(\theta) = \frac{2}{m} X^T (X\theta - y)
$$</p>
<hr />
<h2>7. Normal Equation</h2>
<p>Closed-form solution:</p>
<p>$$
\theta^* = (X^T X)^{-1} X^T y
$$</p>
<hr />
<h2>8. Regularization</h2>
<p>L2 regularization:</p>
<p>$$
J(\theta) = \frac{1}{m} \sum (h_\theta(x) - y)^2 + \lambda |\theta|_2^2
$$</p>
<hr />
<h2>9. Probabilistic View</h2>
<p>Assume:</p>
<p>$$
y = \theta^T x + \epsilon
$$</p>
<p>where:</p>
<p>$$
\epsilon \sim \mathcal{N}(0, \sigma^2)
$$</p>
<p>Likelihood:</p>
<p>$$
p(y|x,\theta) = \frac{1}{\sqrt{2\pi\sigma^2}} \exp\left(-\frac{(y - \theta^T x)^2}{2\sigma^2}\right)
$$</p>
<hr />
<h2>10. Neural Networks Extension</h2>
<p>$$
a^{(l)} = \sigma(W^{(l)} a^{(l-1)} + b^{(l)})
$$</p>
<p>Backpropagation:</p>
<p>$$
\frac{\partial J}{\partial W^{(l)}} = \frac{\partial J}{\partial a^{(l)}} \cdot \frac{\partial a^{(l)}}{\partial W^{(l)}}
$$</p>
<hr />
<h2>11. General Learning Objective</h2>
<p>$$
\min_{\theta} ; \mathbb{E}<em>{(x,y)\sim \mathcal{D}} \left[ \ell(h</em>\theta(x), y) \right]
$$</p>
<hr />
<h2>12. Key Insight</h2>
<p>$$
\text{Machine Learning} = \text{Optimization} + \text{Statistics} + \text{Linear Algebra}
$$</p>
<hr />
<h2>Conclusion</h2>
<p>We built the mathematical foundation of machine learning from:</p>
<ul>
<li>Linear models  </li>
<li>Loss functions  </li>
<li>Optimization  </li>
<li>Probability</li>
</ul>
<p>This is the backbone of modern AI systems.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[AtCoder Beginner Contest 452]]></title><description><![CDATA[AtCoder Beginner Contest 452 Problem number E solution in python
MOD = 998244353
N, M = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
N ]]></description><link>https://ossm.me/atcoder-beginner-contest-452</link><guid isPermaLink="true">https://ossm.me/atcoder-beginner-contest-452</guid><dc:creator><![CDATA[Sumit Mishra]]></dc:creator><pubDate>Sat, 18 Apr 2026 04:21:10 GMT</pubDate><content:encoded><![CDATA[<p>AtCoder Beginner Contest 452 Problem number E solution in python</p>
<pre><code class="language-python">MOD = 998244353
N, M = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
N += 1

S = [t:=0] + [t:=t+a for a in A]

sa = sb = 0
for i in range(N):
  sa = (sa + A[i]*i)%MOD
for j in range(1, M+1):
  sb = (sb + B[j])%MOD
ans = sa*sb%MOD

for j in range(1, M+1):
  for l in range(0, N, j):
    r = min(N, l+j)
    ans = (ans - (S[r]-S[l])*l*B[j])%MOD

print(ans)
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Atcoder ABC problem A Solution]]></title><description><![CDATA[this is the brute forse solution, just need to read the problem and write the simple solution and that's it
import sys
input = sys.stdin.readline

def solve():
    n = int(input())
    c = input().str]]></description><link>https://ossm.me/atcoder-abc-problem-a-solution</link><guid isPermaLink="true">https://ossm.me/atcoder-abc-problem-a-solution</guid><dc:creator><![CDATA[Sumit Mishra]]></dc:creator><pubDate>Sat, 18 Apr 2026 04:16:34 GMT</pubDate><content:encoded><![CDATA[<p>this is the brute forse solution, just need to read the problem and write the simple solution and that's it</p>
<pre><code class="language-Python">import sys
input = sys.stdin.readline

def solve():
    n = int(input())
    c = input().strip()

    result = c.lstrip('o')
    print(result)

solve()
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Ad Hoc Problems]]></title><description><![CDATA[In Latin, ad hoc literally means "for this" — something created or done for a specific purpose, without following any general template or methodology. In the context of programming and competitive pro]]></description><link>https://ossm.me/ad-hoc-problems</link><guid isPermaLink="true">https://ossm.me/ad-hoc-problems</guid><dc:creator><![CDATA[Sumit Mishra]]></dc:creator><pubDate>Sat, 18 Apr 2026 03:47:17 GMT</pubDate><content:encoded><![CDATA[<p>In Latin, <strong>ad hoc</strong> literally means <em>"for this"</em> — something created or done for a specific purpose, without following any general template or methodology. In the context of programming and competitive problem-solving, an <strong>ad hoc problem</strong> is one that doesn't fit neatly into any known algorithmic category.</p>
<p>There's no standard dynamic programming formulation. No graph to traverse. No well-known data structure to reach for. You won't find the answer by applying the right textbook algorithm — because there isn't one. Instead, you must carefully read the problem, think from first principles, and craft a custom solution tailored exactly to what's being asked.</p>
<p>Ad hoc problems are the programming equivalent of a puzzle that has never been seen before. They show up in competitive programming contests, coding interviews, university coursework, and real-world engineering. They are both the simplest and sometimes the most frustrating category of problems — because the only tool you have is your own reasoning.</p>
<h2>A Brief History of the Term in Programming</h2>
<p>The phrase "ad hoc" entered the competitive programming lexicon through platforms like the <strong>ACM International Collegiate Programming Contest (ICPC)</strong> in the 1970s and 80s, where judges categorised problems by the techniques required to solve them. Problems involving sorting, graphs, or dynamic programming were easy to label. The ones that required original thinking — problems that resisted categorisation — were grouped together as "ad hoc."</p>
<p>Over time, platforms like <strong>SPOJ</strong>, <strong>Codeforces</strong>, <strong>UVa Online Judge</strong>, and <strong>HackerRank</strong> formalised the tag. Today, virtually every competitive programming archive uses "ad hoc" as an official problem category, typically meaning: <em>this problem requires careful analysis and creative implementation, not a known algorithm.</em></p>
<h2>What Makes a Problem "Ad Hoc"?</h2>
<p>A problem is generally called ad hoc when:</p>
<ul>
<li><strong>No standard algorithm directly solves it.</strong> You can't just reach for BFS, Dijkstra's, or knapsack DP.</li>
<li><strong>The logic is unique to the problem's setup.</strong> Each ad hoc problem tends to have its own internal rules that you must honour.</li>
<li><strong>The solution is often simpler than it looks</strong> — once you understand it. Many ad hoc problems reward a clear reading of the problem statement more than any algorithmic sophistication.</li>
<li><strong>Simulation is sometimes enough.</strong> Many ad hoc solutions are just careful, literal simulations of what the problem describes.</li>
</ul>
<p>The difficulty isn't computational complexity — it's <em>comprehension and creativity</em>. You have to model the problem correctly in your head before you can model it in code.</p>
<h2>Categories Within Ad Hoc</h2>
<p>Although ad hoc problems resist categorisation by definition, they tend to cluster around a few recurring themes:</p>
<h3>1. Simulation</h3>
<p>You're told: "A system behaves like this. What is its state after N steps?"</p>
<p>The solution is to faithfully simulate the described process. The trick is usually identifying the right state representation and handling edge cases correctly. Simulation problems reward careful reading over clever algorithms.</p>
<p><strong>Example flavour:</strong> A game board moves pieces according to described rules. Given an initial configuration and a sequence of moves, output the final board.</p>
<h3>2. String and Pattern Manipulation</h3>
<p>You're given a string and must detect, transform, or validate some pattern. This could be checking for palindromes, counting occurrences of substrings, or parsing custom-formatted input.</p>
<p>Unlike problems that require the KMP or Aho-Corasick algorithm (which are classified separately), ad hoc string problems can usually be solved with basic iteration and conditionals.</p>
<p><strong>Example flavour:</strong> Given a sentence, count how many words have more vowels than consonants.</p>
<h3>3. Geometry and Spatial Reasoning</h3>
<p>Simple geometry problems — not requiring computational geometry algorithms like convex hull or sweep line — fall into ad hoc territory. These might involve checking if a point is inside a shape, computing distances, or finding intersections.</p>
<p><strong>Example flavour:</strong> Given the coordinates of a rectangle and a point, determine whether the point lies strictly inside, on the border, or outside.</p>
<h3>4. Mathematics Without Heavy Theory</h3>
<p>Some ad hoc problems involve arithmetic, divisibility, number properties, or sequences — but not the deep number theory you'd find on Project Euler. These require mathematical thinking but not advanced theorems.</p>
<p><strong>Example flavour:</strong> Given a number N, find the smallest number greater than N that reads the same forwards and backwards (a palindrome).</p>
<h3>5. Sorting and Searching with a Twist</h3>
<p>The data needs to be sorted or searched, but with a non-standard comparison or multi-criteria ranking that you must define yourself.</p>
<p><strong>Example flavour:</strong> Sort a list of people by last name, but break ties by first name in reverse, and then by age if the names are identical.</p>
<h3>6. Construction and Generation</h3>
<p>Build something that satisfies a set of constraints — a sequence, a grid, a permutation — without a known formula for doing so.</p>
<p><strong>Example flavour:</strong> Arrange the numbers 1 through N² in an N×N grid such that every row, column, and diagonal has the same sum (a magic square).</p>
<h2>The Anatomy of an Ad Hoc Solution</h2>
<p>What does solving an ad hoc problem actually look like? The process tends to follow a predictable rhythm:</p>
<h3>Step 1: Read Slowly and Carefully</h3>
<p>Ad hoc problems are often tricky because of subtleties buried in the problem statement. A single word — "strictly greater," "at most," "non-empty" — can change everything. Read twice before writing a single line of code.</p>
<h3>Step 2: Work Through the Examples by Hand</h3>
<p>Don't trust your first mental model. Take the given examples and trace through them manually. Make sure you can reproduce the expected output before attempting to code it.</p>
<h3>Step 3: Identify the Core Logic</h3>
<p>Ask: what is the fundamental operation this problem is asking me to perform? Strip away the narrative and find the mathematical or logical kernel. Once you can state the core operation in one sentence, you're ready to code.</p>
<h3>Step 4: Handle Edge Cases Explicitly</h3>
<p>Most ad hoc problems are won or lost on edge cases: empty inputs, single elements, maximum values, negative numbers, strings with only spaces. Think adversarially — what would break your solution?</p>
<h3>Step 5: Write and Test</h3>
<p>Ad hoc solutions are often surprisingly short — sometimes fewer than 20 lines. The complexity is intellectual, not syntactic. Write clean, readable code. If your solution is growing unwieldy, it's often a sign that you've misunderstood something fundamental.</p>
<hr />
<h2>A Walkthrough: Classic Ad Hoc Problem</h2>
<p>Let's look at a typical ad hoc problem and walk through solving it.</p>
<p><strong>Problem Statement:</strong></p>
<blockquote>
<p>You are given a 12-hour digital clock that displays hours and minutes (e.g., <code>3:07</code>). The clock is broken: it displays the correct time exactly once every 12 hours, but gains exactly K minutes every hour. Given the time displayed right now and the value of K, what is the actual correct time?</p>
</blockquote>
<p><strong>Analysis:</strong>
This doesn't fit any standard algorithm. It's a simple arithmetic problem, but you need to model the broken clock's behaviour carefully.</p>
<p>If the clock gains K minutes per hour, then after H hours have passed since the clock showed the correct time, the clock shows <code>(actual time) + H * K minutes</code>. We need to reverse-engineer the actual time.</p>
<p><strong>Solution approach (Python):</strong></p>
<pre><code class="language-python">def solve(display_h, display_m, K):
    display_total = display_h * 60 + display_m
    
    for h in range(12 * 60):  # actual time from 0..719 minutes
        drift = (h // 60) * K  # clock has gained this many minutes
        shown = (h + drift) % (12 * 60)
        if shown == display_total:
            actual_h = h // 60
            actual_m = h % 60
            print(f"Actual time: {actual_h}:{actual_m:02d}")
            return

display_h, display_m, K = 4, 30, 15
solve(display_h, display_m, K)
</code></pre>
<p>No graph, no DP, no fancy data structure. Just careful modelling of the described system and a simple loop. That's ad hoc.</p>
<h2>Ad Hoc vs. Other Problem Types</h2>
<p>Understanding where ad hoc ends and other categories begin helps you reason about what techniques to reach for:</p>
<table>
<thead>
<tr>
<th>Problem Type</th>
<th>Key Characteristic</th>
<th>Technique Required</th>
</tr>
</thead>
<tbody><tr>
<td>Ad hoc</td>
<td>Unique logic, no general template</td>
<td>Custom reasoning + simulation</td>
</tr>
<tr>
<td>Graph</td>
<td>Nodes, edges, connectivity</td>
<td>BFS, DFS, Dijkstra, Floyd-Warshall</td>
</tr>
<tr>
<td>Dynamic Programming</td>
<td>Overlapping subproblems</td>
<td>Memoisation, tabulation</td>
</tr>
<tr>
<td>Number Theory</td>
<td>Primes, divisors, modular math</td>
<td>Sieve, Euler's theorem, CRT</td>
</tr>
<tr>
<td>Greedy</td>
<td>Locally optimal choices</td>
<td>Sorting + decision rules</td>
</tr>
<tr>
<td>Geometry</td>
<td>Coordinates, shapes, angles</td>
<td>Convex hull, sweep line</td>
</tr>
</tbody></table>
<p>In practice, the boundaries blur. A problem might be "mostly ad hoc" with one DP component. Classification is a tool for thinking, not a rigid taxonomy.</p>
<h2>Where Do Ad Hoc Problems Appear?</h2>
<h3>Competitive Programming</h3>
<p>Every major contest platform — <strong>Codeforces</strong>, <strong>LeetCode</strong>, <strong>AtCoder</strong>, <strong>CodeChef</strong>, <strong>SPOJ</strong> — has an ad hoc category. In rated contests, ad hoc problems often appear as the first one or two problems: approachable for everyone, but occasionally containing traps for those who rush.</p>
<h3>Coding Interviews</h3>
<p>Many interview problems at tech companies are essentially ad hoc. When an interviewer asks you to parse a custom-formatted string, simulate a board game, or implement a non-standard comparator, they're testing your ad hoc reasoning — your ability to think clearly without a predetermined template.</p>
<h3>University Assignments</h3>
<p>CS courses frequently assign ad hoc problems to test whether students can translate a natural-language specification into working code. The goal isn't to teach a specific algorithm — it's to teach the skill of problem modelling.</p>
<h3>Real-World Engineering</h3>
<p>The real world is full of ad hoc problems. Writing a script to reformat a legacy dataset, implementing a custom validation rule for a business process, or building a small interpreter for an internal DSL — these all require the same skills: read carefully, model accurately, implement cleanly, handle edge cases.</p>
<h2>Why Ad Hoc Problems Are Valuable</h2>
<h3>They Test Thinking, Not Pattern Matching</h3>
<p>Many algorithmic problems can be "solved" by pattern matching: "this looks like a shortest path problem, so I'll use Dijkstra." Ad hoc problems break this shortcut. You can't match a pattern you've never seen. You have to actually think.</p>
<h3>They Reward Reading Comprehension</h3>
<p>A significant percentage of failed ad hoc submissions are wrong not because of an algorithm bug, but because the solver misunderstood the problem. Reading carefully and precisely is a professional skill, and ad hoc problems sharpen it.</p>
<h3>They're Great for Beginners</h3>
<p>Ironically, ad hoc problems are among the most accessible for newcomers to competitive programming, precisely because they don't require advanced knowledge. A beginner with good logical thinking can solve an ad hoc problem that stumps someone who knows many algorithms but hasn't developed their reasoning skills.</p>
<h3>They Build Resilience</h3>
<p>Facing a problem you have no template for and working through it anyway is a confidence-building experience. Every programmer will eventually encounter something genuinely new. Ad hoc practice is training for exactly that moment.</p>
<h2>Common Pitfalls</h2>
<p><strong>1. Over-engineering the solution</strong>
Ad hoc problems often have simple solutions. If you find yourself reaching for a complex data structure or multi-stage algorithm, step back. You may have overcomplicated the model.</p>
<p><strong>2. Ignoring edge cases in the problem statement</strong>
The example test case usually doesn't cover every edge case. Systematically ask: what if the input is empty? What if all values are equal? What if the answer is 0?</p>
<p><strong>3. Integer overflow and off-by-one errors</strong>
These are the most common bug types in ad hoc problems. Be precise about whether bounds are inclusive or exclusive, and check whether your integer types can hold the maximum possible value.</p>
<p><strong>4. Misreading the output format</strong>
The problem says "print the answer with no trailing space." You print a trailing space. Wrong answer. Read the output specification as carefully as the problem statement.</p>
<h2>Tips for Getting Better at Ad Hoc</h2>
<ol>
<li><strong>Solve lots of them.</strong> There's no shortcut — exposure builds intuition for how these problems are structured.</li>
<li><strong>Don't look at solutions immediately.</strong> Sit with a hard problem for at least 30 minutes before checking hints. The discomfort is the training.</li>
<li><strong>Annotate what tripped you up.</strong> Keep a log of edge cases and misreadings. You'll notice patterns in your own mistakes.</li>
<li><strong>Practice on UVa Online Judge or SPOJ.</strong> Both have large archives of classic ad hoc problems with an established community of solvers.</li>
<li><strong>Simulate by hand before coding.</strong> Writing a few steps of the simulation on paper often reveals the logic more clearly than staring at code.</li>
<li><strong>Embrace simplicity.</strong> The best ad hoc solutions are often remarkably plain. A clean loop with good variable names beats a "clever" trick that's hard to verify.</li>
</ol>
<h2>Ad Hoc in the Bigger Picture</h2>
<p>If you think of programming skills as a tree, ad hoc problem solving is the roots. It's not glamorous — nobody becomes famous for their ad hoc solutions — but it underpins everything else. The ability to read a specification, model it precisely, handle its edge cases, and implement it cleanly is the foundation upon which all other programming skills are built.</p>
<p>Dynamic programming is dazzling. Graph algorithms are elegant. But when you encounter something that doesn't fit any box, when the problem is genuinely novel and your experience offers no direct template — that's when ad hoc thinking saves you. And that moment comes far more often than you'd expect.</p>
<p>The next time you're handed a problem and you think, <em>"I don't know what category this is"</em> — congratulations. You've just found an ad hoc problem. Now sit down, read carefully, and figure it out.</p>
<h2>Resources to Practice</h2>
<table>
<thead>
<tr>
<th>Platform</th>
<th>Notes</th>
</tr>
</thead>
<tbody><tr>
<td><a href="https://onlinejudge.org/">UVa Online Judge</a></td>
<td>Huge archive, classic ad hoc problems</td>
</tr>
<tr>
<td><a href="https://codeforces.com/">Codeforces</a></td>
<td>Tags include "implementation" and "ad hoc"</td>
</tr>
<tr>
<td><a href="https://www.spoj.com/">SPOJ</a></td>
<td>Many classic ad hoc problems</td>
</tr>
<tr>
<td><a href="https://leetcode.com/">LeetCode</a></td>
<td>"Simulation" and "string" tags cover similar territory</td>
</tr>
<tr>
<td><a href="https://atcoder.jp/">AtCoder</a></td>
<td>Beginner contests (ABC) start with excellent ad hoc problems</td>
</tr>
</tbody></table>
<hr />
<p><em>Ad hoc is not a weakness in your toolkit. It is the toolkit, before the toolkit exists.</em></p>
]]></content:encoded></item><item><title><![CDATA[Project Euler]]></title><description><![CDATA[What Is Project Euler?
Project Euler is a collection of challenging mathematical and computational problems designed to be solved with the help of programming. Named after the legendary Swiss mathemat]]></description><link>https://ossm.me/project-euler</link><guid isPermaLink="true">https://ossm.me/project-euler</guid><dc:creator><![CDATA[Sumit Mishra]]></dc:creator><pubDate>Sat, 18 Apr 2026 02:27:52 GMT</pubDate><content:encoded><![CDATA[<hr />
<h2>What Is Project Euler?</h2>
<p><strong>Project Euler</strong> is a collection of challenging mathematical and computational problems designed to be solved with the help of programming. Named after the legendary Swiss mathematician <strong>Leonhard Euler</strong> (1707–1783), the project was launched in <strong>October 2001</strong> by Colin Hughes (known online as <em>euler</em>) as a way to bridge the gap between recreational mathematics and computer programming.</p>
<p>At its core, Project Euler is a platform where you are given a problem — sometimes deceptively simple-looking — and you must write a program to compute the answer. The problems range from approachable puzzles for beginners to formidable challenges that require deep mathematical insight and highly optimized algorithms.</p>
<p>The website lives at <a href="https://projecteuler.net">projecteuler.net</a> and currently hosts <strong>over 900 problems</strong>, with new ones added regularly.</p>
<hr />
<h2>The Origin Story</h2>
<p>The project began as a supplementary tool for a UK-based study group, but word spread quickly through online mathematics and programming communities. By the mid-2000s, it had become a global phenomenon, with participants from virtually every country solving problems in dozens of different programming languages.</p>
<p>Leonhard Euler — the project's namesake — was one of the most prolific mathematicians in history. He made foundational contributions to graph theory, number theory, calculus, and topology. Naming the project after him was a fitting tribute, as many problems on the site draw directly from areas of mathematics he helped define.</p>
<hr />
<h2>How It Works</h2>
<h3>The Problem Format</h3>
<p>Each problem on Project Euler follows a consistent structure:</p>
<ol>
<li><strong>A narrative setup</strong> — Usually a short paragraph that introduces the mathematical scenario.</li>
<li><strong>A small worked example</strong> — Demonstrates the concept with a trivial case you can verify by hand.</li>
<li><strong>The actual challenge</strong> — The same question but scaled up dramatically, making manual computation impossible.</li>
</ol>
<p>For example, a problem might say:</p>
<blockquote>
<p><em>"The sum of the natural numbers below 10 that are multiples of 3 or 5 are 3, 5, 6, and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1,000."</em></p>
</blockquote>
<p>The small example (below 10) you can do in your head. The real problem (below 1,000) requires a program — but a simple loop will do. Later problems require far more sophisticated approaches.</p>
<h3>The Answer</h3>
<p>Every problem has a <strong>single numerical answer</strong>. You enter it into the website, and it either accepts or rejects it. There is no partial credit, no explanation required — just the number.</p>
<p>This design philosophy is intentional: it puts all the creative pressure on <em>how</em> you get there.</p>
<h3>The One-Minute Rule</h3>
<p>Project Euler has an informal but widely respected guideline: your solution should run in <strong>under one minute</strong> on a reasonably modern computer. This isn't enforced by the platform, but it's a cultural norm that pushes solvers toward elegant, efficient solutions rather than brute-force hacks.</p>
<hr />
<h2>Why Do People Love It?</h2>
<h3>1. The "Aha!" Moment</h3>
<p>Many Project Euler problems are designed so that the naive approach is far too slow. You might write a solution that works but would take years to compute. Then, you discover a mathematical insight — a pattern, a theorem, a smarter representation — and suddenly your solution runs in milliseconds. That transition from "this will never finish" to "done in 0.003 seconds" is genuinely thrilling.</p>
<h3>2. Language Agnostic</h3>
<p>You can solve Project Euler problems in <strong>any programming language</strong>: Python, C++, Java, Haskell, Rust, JavaScript, Julia, even MATLAB or Excel if you're creative. This makes it a fantastic playground for learning a new language — you already know what the answer should be, so you can focus entirely on learning the language's syntax and idioms.</p>
<h3>3. Self-Paced Learning</h3>
<p>There are no deadlines, no grading, no pressure. You can spend an hour on a problem or three weeks. Some people blaze through the first 50 problems in a weekend; others savor one problem a month. The platform respects your pace completely.</p>
<h3>4. A Sense of Community</h3>
<p>After solving a problem, you unlock access to a <strong>discussion forum</strong> for that problem, where thousands of other solvers share their approaches. Reading these threads is often as educational as solving the problem itself — you see the same problem attacked from a dozen different angles, in different languages, with wildly different levels of mathematical sophistication.</p>
<h3>5. The Gamification Element</h3>
<p>Each problem you solve adds to your count on your profile. There are <strong>achievement levels</strong>, and the community maintains unofficial leaderboards. Crossing milestones like solving 25, 50, or 100 problems is genuinely motivating.</p>
<hr />
<h2>The Mathematics Behind the Problems</h2>
<p>Project Euler problems are deeply rooted in classical mathematics. Here are some of the major themes you'll encounter:</p>
<h3>Number Theory</h3>
<ul>
<li>Prime numbers and primality testing</li>
<li>Greatest common divisors and least common multiples</li>
<li>Modular arithmetic</li>
<li>Euler's totient function</li>
<li>The Sieve of Eratosthenes</li>
</ul>
<h3>Combinatorics and Probability</h3>
<ul>
<li>Counting permutations and combinations</li>
<li>Pascal's triangle and binomial coefficients</li>
<li>Random walks and expected values</li>
</ul>
<h3>Dynamic Programming and Recursion</h3>
<ul>
<li>Fibonacci sequences and recurrence relations</li>
<li>Lattice path counting</li>
<li>Coin change and subset sum problems</li>
</ul>
<h3>Geometry and Algebra</h3>
<ul>
<li>Pythagorean triples</li>
<li>Continued fractions</li>
<li>Diophantine equations</li>
<li>Polygonal numbers (triangular, pentagonal, hexagonal, etc.)</li>
</ul>
<h3>Cryptography and Encoding</h3>
<ul>
<li>ASCII encoding and XOR ciphers</li>
<li>Pangrams and text analysis</li>
</ul>
<h3>Calculus and Analysis</h3>
<ul>
<li>Convergent series</li>
<li>Digit sums and digit products</li>
<li>Infinite continued fractions</li>
</ul>
<hr />
<h2>A Walkthrough: Problem 1</h2>
<p>Let's walk through the very first problem to see the Project Euler experience in action.</p>
<p><strong>Problem Statement:</strong></p>
<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>
<p><strong>Naive Solution (Python):</strong></p>
<pre><code class="language-python">total = 0
for i in range(1000):
    if i % 3 == 0 or i % 5 == 0:
        total += i
print(total)  # 233168
</code></pre>
<p>This works perfectly and runs instantly for 1,000. But what if the problem asked for numbers below 1,000,000,000? The loop would be too slow.</p>
<p><strong>Mathematical Solution (Using the Inclusion-Exclusion Principle):</strong></p>
<p>The sum of all multiples of <em>k</em> below <em>n</em> is:</p>
<pre><code>k * (1 + 2 + 3 + ... + floor((n-1)/k))
= k * m*(m+1)/2   where m = floor((n-1)/k)
</code></pre>
<p>We compute the sum of multiples of 3, plus the sum of multiples of 5, minus the sum of multiples of 15 (to avoid double-counting):</p>
<pre><code class="language-python">def sum_multiples(k, n):
    m = (n - 1) // k
    return k * m * (m + 1) // 2

result = sum_multiples(3, 1000) + sum_multiples(5, 1000) - sum_multiples(15, 1000)
print(result)  # 233168
</code></pre>
<p>This runs in <strong>O(1)</strong> time — instant for any <em>n</em>, no matter how large. That's the Project Euler experience in one problem.</p>
<hr />
<h2>Difficulty Levels and Progression</h2>
<p>Problems are rated by an approximate <strong>difficulty percentage</strong> (the percentage of solvers who found it challenging). The first ~50 problems are relatively accessible; by problem 100, you're regularly encountering topics like Gaussian integers, elliptic curves, or advanced dynamic programming.</p>
<table>
<thead>
<tr>
<th>Problem Range</th>
<th>Typical Difficulty</th>
<th>Skills Needed</th>
</tr>
</thead>
<tbody><tr>
<td>1–25</td>
<td>Beginner</td>
<td>Loops, basic math, primes</td>
</tr>
<tr>
<td>26–75</td>
<td>Intermediate</td>
<td>Number theory, recursion, DP</td>
</tr>
<tr>
<td>76–150</td>
<td>Advanced</td>
<td>Combinatorics, algebraic structures</td>
</tr>
<tr>
<td>150–300</td>
<td>Expert</td>
<td>Research-level math, deep algorithms</td>
</tr>
<tr>
<td>300+</td>
<td>Competition-level</td>
<td>Original mathematical insight</td>
</tr>
</tbody></table>
<hr />
<h2>Project Euler vs. Other Competitive Programming Platforms</h2>
<p>Project Euler is often compared to platforms like LeetCode, HackerRank, or Codeforces. Here's how it differs:</p>
<table>
<thead>
<tr>
<th>Feature</th>
<th>Project Euler</th>
<th>LeetCode / HackerRank</th>
</tr>
</thead>
<tbody><tr>
<td>Focus</td>
<td>Mathematics + programming</td>
<td>Algorithms + data structures</td>
</tr>
<tr>
<td>Answer format</td>
<td>Single number</td>
<td>Code submission with test cases</td>
</tr>
<tr>
<td>Time pressure</td>
<td>None (self-paced)</td>
<td>Sometimes (contests)</td>
</tr>
<tr>
<td>Language freedom</td>
<td>Fully language-agnostic</td>
<td>Restricted by judge</td>
</tr>
<tr>
<td>Community discussion</td>
<td>After solving</td>
<td>Always visible</td>
</tr>
<tr>
<td>Problem count</td>
<td>800+ (math-heavy)</td>
<td>Thousands (CS-heavy)</td>
</tr>
</tbody></table>
<p>Project Euler is better suited for people who love mathematics and want to deepen that love through programming. The other platforms are better for interview prep and competitive programming.</p>
<hr />
<h2>Who Is It For?</h2>
<p>Project Euler has an incredibly diverse audience:</p>
<ul>
<li><strong>Students</strong> learning to program who want meaningful problems to practice on</li>
<li><strong>Mathematicians</strong> who want to explore ideas computationally without deep CS background</li>
<li><strong>Software engineers</strong> who want to sharpen algorithmic thinking</li>
<li><strong>Hobbyists</strong> who simply enjoy puzzles and the satisfaction of a correct answer</li>
<li><strong>Teachers</strong> who use problems as curriculum material</li>
<li><strong>Language learners</strong> who use problems as a benchmark when picking up a new language</li>
</ul>
<hr />
<h2>Tips for Getting Started</h2>
<ol>
<li><strong>Start with Problem 1, not a random one.</strong> The early problems scaffold skills you'll need later.</li>
<li><strong>Don't rush to look up solutions.</strong> The struggle is the point. Even spending two days on a problem and failing teaches you something.</li>
<li><strong>Write readable code first, optimize second.</strong> Get a correct answer, then think about whether it can be made faster.</li>
<li><strong>Keep a math reference handy.</strong> Wikipedia and Wolfram MathWorld are your friends. Don't be afraid to look up a theorem — the skill is in applying it, not memorizing it.</li>
<li><strong>After solving, read the forum.</strong> Seeing five other approaches to the same problem expands your thinking enormously.</li>
<li><strong>Don't be discouraged by the difficulty jump.</strong> Problems 1–10 are manageable. Problem 14 (Collatz sequence) catches many people off guard. That's normal.</li>
</ol>
<hr />
<h2>The Legacy and Impact</h2>
<p>Over 20 years after launch, Project Euler remains one of the most beloved platforms in the mathematical programming community. It has:</p>
<ul>
<li><strong>Over 1 million registered accounts</strong></li>
<li>Problems solved in <strong>hundreds of programming languages</strong></li>
<li>Spawned countless blog posts, YouTube series, and university courses</li>
<li>Inspired similar projects like <strong>Advent of Code</strong>, <strong>SPOJ</strong>, and <strong>Rosalind</strong> (for bioinformatics)</li>
</ul>
<p>More importantly, it has introduced countless people to the idea that mathematics isn't just something you study in school — it's a living, playful, endlessly surprising discipline that comes alive when you can <em>compute</em> with it.</p>
<hr />
<h2>Final Thoughts</h2>
<p>Project Euler occupies a unique space in the world of programming challenges. It doesn't care what language you use, how long you take, or how elegant your code looks. It only cares about one thing: <strong>did you understand the problem deeply enough to find the answer?</strong></p>
<p>That single focus strips away a lot of noise and gets at something fundamental — the pure pleasure of understanding. Each solved problem is a small proof of competence, a receipt for time well spent thinking carefully about how numbers, patterns, and algorithms behave.</p>
<p>Whether you're a seasoned developer looking for a mental workout, a student just learning to code, or a lifelong math enthusiast who never quite learned to program, Project Euler has a problem waiting for you.</p>
<p>Go solve something.</p>
<hr />
<p><em>Start your Project Euler journey at <a href="https://projecteuler.net">projecteuler.net</a></em></p>
]]></content:encoded></item></channel></rss>