Researchers have discovered the mathematical pattern that allows thousands of synchronized fireflies light up the night.