A self-optimizing algorithm for precise nanocrystal synthesis