Skip to content

Instantly share code, notes, and snippets.

@trevorsibanda
Created June 29, 2017 13:36
Show Gist options
  • Save trevorsibanda/3471f43a2b9b64bb6970a642e46b286a to your computer and use it in GitHub Desktop.
Save trevorsibanda/3471f43a2b9b64bb6970a642e46b286a to your computer and use it in GitHub Desktop.
def ?(r: Int, ops: Seq[Char], nums: Seq[Int]):Int=if(ops.isEmpty)r else ?(ops.head match{case '+' => r+nums.head; case '-' => r-nums.head}, ops.tail, nums.tail); (1 to 9).map{i=>"123456789".grouped(i).toList}.map{_.map{_.toInt}}match{ case l => l.zip((1 to l.length).permutations.toList.map{_.map{i => if(i%2 == 0) '+' else '-'})}.map{x=> (?(0, x._1, x._2), x)}}.filter(_ != 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment