Python code from Peter Norvig and Stuart Russell's Artificial Intelligence, A Modern Approach