How the Drone Finds the Best Sunflower — The Coding Concept Behind Farmer Ep 5
The drone can farm a 12×12 grid. It can rotate crops, time harvests, and handle pumpkins that rot if you ignore them.
But in Episode 5 of I Taught an AI to Farm, it hits something new: not all sunflowers are equal. Some are big and ready to harvest. Some are small and not worth picking yet. The drone needs to find the ONE sunflower worth harvesting — and that means scanning, comparing, and picking the winner.
That process is one of the most useful ideas in all of programming.
▶ Watch: I Taught A Drone to Spot the Best Sunflower
The problem in plain English
Imagine you're at a market looking for the freshest apple. There are 12 stalls. You can't buy one from each stall and decide later — you need to pick one.
What do you do? You walk the stalls one by one. You pick up the first apple: "Is this good enough?" Then you move to the next one. If it looks better, it becomes your new favourite. If not, you move on. By the time you've seen all 12, you've got the best one.
That's exactly what the drone does. It's also exactly what max() does in Python.
What max() actually is
max() is a built-in shortcut that does the market walk for you. Give it a list of numbers and it returns the biggest one:
sunflowers = [3, 7, 2, 9, 4]
best = max(sunflowers)
# best = 9
One line. Done.
But the interesting part isn't the function — it's why this works and what it's doing under the hood.
Scanning and comparing, step by step
Here's the same idea written out long-hand so you can see what's happening:
sunflowers = [3, 7, 2, 9, 4]
best_so_far = sunflowers[0] # Start with the first one
for sunflower in sunflowers:
if sunflower > best_so_far:
best_so_far = sunflower
# best_so_far = 9
Step by step:
- Start with the first sunflower as your current best.
- Check each one in the list.
- If it beats your current best, it becomes the new best.
- At the end,
best_so_farholds the winner.
max() is doing exactly this — Python just handles the loop for you.
Where this pattern shows up
Once you understand this, you start spotting it everywhere:
- Leaderboards — find the highest score in a list of players
- Shopping apps — find the cheapest item from a list of prices
- Weather — find the hottest day in a 7-day forecast
- Game AI — find the best move available from a list of options
The drone's sunflower problem is the same shape as all of those. One scan, one winner.
The bigger idea: prioritising
What makes Episode 5 interesting isn't just the code. It's the shift in how the drone thinks.
Before Ep 5, the drone was doing everything: harvest everything ready, rotate all crops, check all cells. In Ep 5, it has to prioritise — not "harvest everything", but "harvest the best one". That's a different kind of decision.
Moving from "do everything" to "pick the best option" is a big step in how programs learn to make useful choices. You'll see this shift again when we get to game AI, search algorithms, and anything that has to choose between options.
Watch the full episode
▶ Watch: I Taught A Drone to Spot the Best Sunflower
The video walks through the drone's logic from the inside — you'll see the scanning code in action across the full 12×12 grid. This is Episode 5 of the I Taught an AI to Farm series.