def min_conflicts(csp, max_steps=<NUM_LIT>):
<EOL>csp.current = current = {}<EOL>for var in csp.vars:<EOL><INDENT>val = min_conflicts_value(csp, var, current)<EOL>csp.assign(var, val, current)<EOL><DEDENT>for i in range(max_steps):<EOL><INDENT>conflicted = csp.conflicted_vars(current)<EOL>if not conflicted:<EOL><INDENT>return current<EOL><DEDENT>var = random.choice(conflicted)<EOL>val = min_conflicts_value(csp, var, current)<EOL>csp.assign(var, val, current)<EOL><DEDENT>return None<EOL>
Solve a CSP by stochastic hillclimbing on the number of conflicts.