Recursion: how to avoid Python set changed set during iteration RuntimeError

I think the problem is here: for color in self.domains[var]: if not self._valid(var, color): continue self.map[var].color = color for key in node.neighbors: if color in self.domains[key]: self.domains[key].remove(color) # This is potentially bad. if key == var when self.domains[key].remove(color) is called, you change the size of the set you’re currently iterating over. You can avoid this … Read more

Using the “Prolog in Scala” to find available type class instances

This can be done (at least in some cases) with compiler internals import scala.language.experimental.macros import scala.reflect.internal.util import scala.reflect.macros.{blackbox, contexts} object Macros { def allImplicits[A]: List[String] = macro impl[A] def impl[A: c.WeakTypeTag](c: blackbox.Context): c.Tree = { import c.universe._ val context = c.asInstanceOf[contexts.Context] val global: context.universe.type = context.universe val analyzer: global.analyzer.type = global.analyzer val callsiteContext = context.callsiteTyper.context … Read more

Solving “Who owns the Zebra” programmatically?

Here’s a solution in Python based on constraint-programming: from constraint import AllDifferentConstraint, InSetConstraint, Problem # variables colors = “blue red green white yellow”.split() nationalities = “Norwegian German Dane Swede English”.split() pets = “birds dog cats horse zebra”.split() drinks = “tea coffee milk beer water”.split() cigarettes = “Blend, Prince, Blue Master, Dunhill, Pall Mall”.split(“, “) # … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)