The Elevator Ride

Difficulty: ★ ★ ★ ☆

I recently stayed at a resort with a tall hotel tower, over 30 stories. As I rode the elevator up to my floor, I thought about how the lift worked like a pointer traversing an array: The floors are elements. Each stop going up represents a passenger’s desired destination, as do stops on the return trip. My programmer brain was on fire!
Continue reading

Simplifying Fractions

Difficulty: ★ ★ ★ ☆

Recently, I wrote code to calculate odds. The program’s output listed the odds as a fraction, such as 1/6 for rolling a specific number on a die. But occasionally, the output is something like 7/21. As a human, and after a modicum of mental sweat, I recognize 7/21 as 1/3. The challenge is how to get the computer to recognize and report the smaller fraction.
Continue reading