Implementing the Deutsch algorithm with atoms and cavities