terminal@charbelk ~/blog/ripe-or-rotting.md
cat ripe-or-rotting.md

Why do fruit flies end up on rotting fruit? I simulated one to find out.

Leave a banana on the counter for a week and the flies show up. The obvious story is that fruit flies love rotting fruit. But I kept wondering whether that's actually true, or whether rotting fruit is just louder. A fermenting banana gives off far more smell than a fresh one, so maybe flies find it from farther away, even if, given the choice right in front of them, they'd rather eat the ripe one.

That's a hard thing to test by watching flies, because smell, taste and hunger are all tangled together. So I tried something different: I built the whole situation in a computer, from the banana's chemistry to the fly's brain, and ran the experiment there.

Simulated fruit flies casting and surging through two turbulent odour plumes toward a ripe and a rotting banana
Hungry simulated flies searching the smell of a ripe (blue) and a rotting (orange) banana. Grey: searching; green: flying upwind because their brain detected the smell; yellow: eating.

Building a fly from the banana up

The rule I set myself was: no made-up "sweetness = 0.7" numbers. Every step had to come from real measurements wherever they exist.

  1. The banana. Starting from the measured composition of a ripe Cavendish banana, the model lets it ripen, or lets yeast colonise it. Yeast eats sugar and makes ethanol and CO₂, bacteria turn some ethanol into vinegar, and the yeast releases fruity by-products. After a week the rotting banana has about 2% alcohol and a pH of 4.3.
  2. The smell leaving the fruit. Each of 11 odour molecules evaporates at a rate set by its own chemistry and the temperature. A week of fermentation multiplies the release of ethyl acetate about 180-fold.
  3. The air. Smell doesn't drift as a smooth cloud. It breaks into wisps that come and go, so a fly downwind smells nothing most of the time, then a sudden burst. The model simulates that turbulence.
  4. The fly's nose and tongue. Measured data on how each of the fly's smell receptors responds to each molecule, and how its taste neurons respond to sugar, bitterness, acid and yeast, turns the chemistry into nerve signals.
  5. The brain. In September 2026 researchers published the complete wiring diagram of a male fruit fly's nervous system: 165,122 neurons and 25.6 million connections. I simulated all of it, in four states: fed, starved, protein-deprived, or both.
  6. The behaviour. Simulated flies fly upwind when their brain detects the smell and zigzag when they lose it, like real flies in wind tunnels. When they land, the brain's taste response decides whether they eat.

The brain didn't work at first

The first surprise was that the simulated brain couldn't smell. Any odour at all, vinegar, fruit, CO₂, lit up the same 4,000 neurons, like a seizure. Every smell looked identical.

Tracing it back, the culprit was a small group of 30 neurons in the fly's smell centre that are wired to excite each other through about 87,000 synapses. In a real fly these neurons mostly talk through electrical contacts that a simple wiring-diagram model doesn't capture. Once I accounted for that, each smell produced its own distinct pattern in the brain. It's a good reminder that a wiring diagram isn't a working brain on its own.

What the simulated fly did

Rotting fruit really is louder. The brain could detect rotting banana at a tenth of the concentration it needed for ripe banana. In a light breeze that means a well-fed fly can pick up rotting banana from roughly 8 to 19 metres away, but ripe banana only from 2 to 6 metres. Warm weather stretches that range further, because fermentation speeds up.

Odour plume field, concentration time series, plume statistics and detection range bars for ripe and rotting banana
The smell a fly meets comes in bursts (A–C). Right: how far away the simulated brain can detect each banana.

Hunger closes the gap. Starving the fly made its brain much more sensitive to the smell channels that ripe banana uses. Released 10 metres downwind, well-fed flies reached the rotting banana first 62 to 70% of the time. Starved flies split 50/50, because they could now smell both.

Up close, smell stops mattering. Within a few metres, both bananas are easily detectable in every wisp of smell. Which fruit a fly lands on first comes down to where the wind happens to carry it: a coin flip, whatever its hunger, the wind speed or the temperature.

Rotting fruit tastes worse, but the yeast on it tastes better. This is the part that answered my original question. The rotting flesh itself was 2 to 4 times less appealing to the fly's brain than ripe flesh: less sugar, and the acid and alcohol dampen its sugar-sensing neurons. So my hunch was right, as far as the fruit goes. But yeast grows in colonies on the surface, and the fly has taste neurons tuned to yeast. Where the fly tastes those colonies, rotting fruit catches up with or beats ripe fruit.

What a fly eats depends on what it's missing. Yeast is a fly's protein source. Protein-deprived flies fed mostly on the rotting fruit. Sugar-starved flies were the least interested in it and happily ate the ripe banana.

> the answer

"Flies love rotting fruit" is really two separate things. Fermentation smells pull well-fed flies in from a distance, and yeast taste pulls protein-hungry flies once they land. Neither is a preference for rot itself. The rotting flesh, on its own, tastes worse.

Where the model is wrong

I checked the simulation against nine things we know about real flies. It passed four, for example correctly predicting how much more sugar-hungry a starved fly becomes on a test it was never tuned to. It also clearly failed three:

  • [FAIL]Predicting which of 108 smells real flies find attractive. Even the fly's raw receptor data couldn't do it.
  • [FAIL]Steering: smell on one side of the head doesn't make the simulated brain turn toward it.
  • [FAIL]In real flies, hunger dramatically increases how often they fly upwind to food. In the model it doesn't.

There are other limits too. Several chemistry values are estimates, the connectome is male (so it can't capture egg-laying females, who crave yeast most), and the flight rules come from real fly data rather than from the simulated brain. So treat the conclusions as predictions, not facts.

What would settle it

The good news is that every prediction here can be tested. Release fed and starved flies 10 metres downwind of a ripe and a yeast-inoculated banana, count where they land first, and separately where they eat, with protein-deprived and smell-blind flies as comparisons. If the model is right, hunger should change where flies land from far away, and protein deprivation should change what they eat.

Everything is open: the paper with all the methods and numbers, and the code and data to rerun it.

cd ..
Back to blog