Principles of Intelligent Behavior in Biological and Social Systems