Last active
August 29, 2015 14:20
-
-
Save eranation/c039ce9e22e04db18d14 to your computer and use it in GitHub Desktop.
Revisions
-
eranation revised this gist
May 8, 2015 . 2 changed files with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ 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("+","-","") val choose1 = for { c1 <- operators This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,7 @@ 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] = { -
eranation created this gist
May 8, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ import javax.script.ScriptEngineManager val operators:Seq[String] = Seq("+","-","") // 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 choose1 = for { c1 <- operators c2 <- operators c3 <- operators c4 <- operators c5 <- operators c6 <- operators c7 <- operators c8 <- operators stringRep = s"1${c1}2${c2}3${c3}4${c4}5${c5}6${c6}7${c7}8${c8}9" result = e.eval(stringRep).asInstanceOf[Double].toInt if result == 100 } yield { stringRep } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ import javax.script.ScriptEngineManager 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 }