import javax.script.ScriptEngineManager // I *could* write an evaluation engine by hand, since it's only + and - it would be dead easy, but... not this time... val e = new ScriptEngineManager().getEngineByName("javascript") val operators:Seq[String] = Seq("+","-","") def operatorPermutations(position:Int):Seq[String] = { if (position > 1) { for { curOp <- operators choose1 = operatorPermutations(position-1) choice<-choose1 strRes = choice + curOp + position.toString } yield { strRes } } else { Seq("1") } } for { option <- operatorPermutations(9) result = e.eval(option).asInstanceOf[Double].toInt if result == 100 } yield { option }