9 "Python" Posts

Rethinking the Three-Second Traffic Rule: When Physics Says It’s Not Enough

While researching why car insurance rates are so extremely high in Las Vegas, I started thinking about the three-second rule and its validity. As I’ve always heard, the three-second rule refers to how far you should be behind a car in traffic. The idea is that you pick out a fixed roadside marker and you are supposed to pass that marker at least three seconds after the car in front of you. That rule is simple enough, yet deceptively deep once you unpack the physics.


“Three seconds is a rule of thumb. Physics reveals the truth.”


Read more →

Modeling Heat Capacity and Evaporation with Python: Why Water Warms Slowly but Cools Fast

Every summer, it feels like a small miracle when the pool finally warms up enough to swim. In Nevada, where the air temperature can sit above 100°F (38°C) for weeks, you’d expect the water to keep pace. Yet, somehow, it takes forever to warm, and only a few cool nights can undo all that progress.

The same phenomenon shows up in a stick of butter. Butter melts quickly, while margarine stays stubbornly firm even under the same heat. That’s not coincidence; it’s thermodynamics.

The butter versus margarine comparison is a staple example in nutrition science. It shows how the proportions of fat, water, and solids affect how much energy it takes to change temperature. Butter, with more fat and less water, heats up and melts quickly. Margarine, full of water and unsaturated oils, absorbs more energy before softening because water’s specific heat is much higher.


“A pool in the desert and a stick of margarine in the kitchen both tell the same story: water resists change.”


Read more →

Numeric Parsing in Python with Integer Division and Modulus

When you need to parse a number, the first instinct is often to convert it to a string and slice it. That works well for data that comes from people — like phone numbers, credit cards, or postal codes — where formatting and leading zeros matter. But when you are working with raw numeric data that is guaranteed to be fixed-width and free of formatting, numeric parsing with integer division (//) and modulus (%) is the better option.


String parsing is flexible, but numeric parsing is faster and cleaner when the data is truly numeric.


Read more →

Using SymPy in Python When NumPy Isn't Enough

Most of us reach for NumPy whenever math shows up in a project. But sometimes, you don’t want approximate answers, you want exact math. That’s when you pull SymPy out of your programmer’s toolkit and get to work.

It’s easy to think of SymPy only in academic terms, like running physics simulations where small rounding errors can snowball into nonsense, or checking algebraic identities where a value such as 0.0000001 should really be treated as exactly 0. Those are valid use cases, but they barely scratch the surface.

In real-world business applications, imprecision can be just as costly. Financial software is the most obvious example, where a few pennies lost to rounding errors can add up to millions at scale. Supply chain and logistics systems can also suffer when tolerances or unit conversions drift slightly off, leading to incorrect shipments or mismatched inventory. Even common scenarios such as pricing models or tax calculations can go sideways if the math behind them is not exact.


“Floats guess. SymPy knows.”


This is where SymPy shines. To see the difference between floating-point approximations (Python or NumPy) and symbolic precision (SymPy), let’s look at a simple but very real example from finance.

Read more →

The Five-Second Rule Explored with Math & Python

You know the story: drop a cookie on the kitchen floor, swoop in before five seconds are up, and declare it safe. It is comforting. It is also wrong.


“Germs don’t wait five seconds. They start the party the instant your food hits the floor.”


The truth is much more interesting than the myth. Germs do transfer gradually, but they are especially fast at the beginning. That means if you want to know whether your floor-cookie is still edible, you need to think in curves, not in timers. And curves are something we can model.

Read more →

The Meeting Diet: An Optimization Approach to Your Calendar

Every week your calendar fills with more meeting invites than you can reasonably handle. Which ones are worth the time and energy, and which should you politely decline? What if there was a way to quantify that choice?


“Your calendar is a knapsack. Every meeting takes space, but only some add enough value to justify carrying them.”


The good news: math can help. By modeling your schedule as a 0/1 knapsack problem with two constraints , you can treat meetings like items with value, time cost, and energy cost. Classic optimization techniques then help decide which meetings to attend. In this post, we’ll walk through framing the problem, prompting AI to scaffold the code, and running a simulation to visualize your optimal “meeting diet.”

Read more →

Using Python Dispatch Tables for Cleaner Validation

Let’s be honest: argument validation code is rarely the proudest part of anyone’s repo.

Most of us start with the usual suspects:

❌ The dreaded inverted-V tower of if/else statements
❌ A graveyard of guard clauses scattered line after line


Using a dispatch table for validation rules means: one dictionary, one loop, infinite sanity.


Both work fine… until they don’t. Then you’re left maintaining a wall of conditionals that feels like it was designed by a committee of goblins.

There’s a better way: dispatch tables!

Read more →

From Ice Shows to Algorithms: Cracking the Truck-Packing Problem

My first full-time programming job was for Holiday on Ice, an international ice show. While I focused mainly on back office systems such as accounting, itinerary, and box office reporting, I knew that one of the biggest technical challenges faced by the show’s crew was efficiently loading trucks for the next city.

“Given the dimensions of a truck and a list of containers (with their dimensions and weight), in what order, position, and orientation should you pack the truck?”


One day, the controller asked me if I could code a system that took, as input, the trucks’ 3D dimensions and the 3D dimensions (and weight) of every object to be packed. Back in the Turbo Pascal era, exploring 3D packing was painful. Today, with Python and AI-assisted scaffolding, it’s surprisingly approachable.

Read more →

Should You Walk or Run in the Rain? The Puzzle That Sparked a Passion

To walk or to run. That is the question. Early in my programming career, I came across a coding challenge that stuck with me for many years: “If it’s raining, will you stay drier by walking or running through it?” At the time, I didn’t have the skillset or tools to simulate the problem properly. It became one of the first exercises that nudged me toward a lifelong fascination with modeling the real world through code.

Read more →