Scala二十四点游戏(9): 完整的代码和计算结果

jerry Scala 2015年11月25日 收藏

综合前面的介绍,这里我们给出最终的24点游戏的代码:

import scala.collection.mutable.Stack

trait BinaryOp{
  val op:String
  def apply(expr1:String,expr2:String) = expr1 + op + expr2
  def unapply(str:String) :Option[(String,String)] ={
    val index=str indexOf (op)
    if(index>0)
      Some(str substring(0,index),str substring(index+1))
    else None
  }
}

class Rational (n:Int, d:Int) {
  require(d!=0)
  private val g =gcd (n.abs,d.abs)
  val numer =n/g
  val denom =d/g
  override def toString = numer + "\\" +denom
  def +(that:Rational)  =
    new Rational(
      numer * that.denom + that.numer* denom,
      denom * that.denom
    )

  def -(that:Rational)  =
    new Rational(
      numer * that.denom - that.numer* denom,
      denom * that.denom
    )

  def * (that:Rational) =
    new Rational( numer * that.numer, denom * that.denom)

  def / (that:Rational) =
    new Rational( numer * that.denom, denom * that.numer)

  def this(n:Int) = this(n,1)
  private def gcd(a:Int,b:Int):Int =
    if(b==0) a else gcd(b, a % b)
}


object Bracket{
  def matchBracket(str:String):Option[(Int,Int)] ={
    val left = str.indexOf('(')
    if(left >=0) {
      val stack = Stack[Char]()
      val remaining = str substring (left+1)
      var index=0
      var right=0
      for(c <-remaining if right==0){
        index=index + 1
        c match{
          case '(' => stack push c
          case ')'  => if (stack isEmpty)  right= left+index else stack pop
          case _ =>
        }

      }

      Some(left,right)
    }else  None
  }

  def apply(part1:String,expr:String,part2:String) =part1+ "(" + expr + ")"+ part2
  def unapply(str:String) :Option[(String,String,String)] ={
     Bracket.matchBracket(str) match{
      case Some((left:Int,right:Int)) =>{
        val part1 = if (left == 0) "" else str substring(0, left )
        val expr = str substring(left + 1, right)
        val part2 = if (right == (str length)-1) "" else str substring (right+1)
        Some(part1, expr, part2)
      }
      case _ => None
    }
  }
}

object Multiply  extends {val op="*"} with BinaryOp
object Divide  extends {val op="/"} with BinaryOp
object Add  extends {val op="+"} with BinaryOp
object Subtract  extends {val op="-"} with BinaryOp
object Rational  extends {val op="\\"} with BinaryOp




object Test extends App{

  val templates=List(
    "N*N-N+N",
    "(N-N)*N*N",
    "N*N+N*N",
    "(N+N)*N*N",
    "N*N*N*N",
    "(N+N*N)*N",
    "(N*N-N)*N",
    "N*N+N+N",
    "(N/N-N)*N",
    "(N-(N-N))*N",
    "N-(N-N-N)",
    "N+N-(N-N)",
    "N*(N/N-N)",
    "(N-N*N)*N",
    "N*(N-N)+N",
    "N+N+N/N",
    "(N-N)*(N-N)",
    "N+N*N/N",
    "N*N/(N-N)",
    "(N+N)*(N+N)",
    "(N-N)*N/N",
    "N+(N+N)/N",
    "N*N/(N+N)",
    "(N+N)*N/N",
    "(N*N+N)*N",
    "(N*N-N)/N",
    "(N/N+N)*N",
    "N*N/N/N",
    "N+N+N-N",
    "N-(N-N)+N",
    "N/(N-N/N)",
    "N+(N-N)*N",
    "(N+N+N)*N",
    "N+N*N-N",
    "N*N-N/N",
    "(N+N)*N-N",
    "(N+N)*(N-N)",
    "(N-N/N)*N",
    "N*(N+N)+N",
    "N*N+N/N",
    "N*N/N-N",
    "(N+N/N)*N",
    "N*N*N/N",
    "(N+N*N)/N",
    "N+N*N+N",
    "N-(N-N)*N",
    "(N-(N+N))*N",
    "N*N-N-N",
    "N+N/N+N",
    "(N-N)*N-N",
    "(N+N)/N+N",
    "N*N+N-N",
    "N/N+N+N",
    "N*N*N-N",
    "(N*N+N)/N",
    "N+N+N*N",
    "N*(N-N)/N",
    "N/N*N+N",
    "N+N*N*N",
    "N+N+N+N",
    "N*N/(N*N)",
    "N+(N+N)*N",
    "(N-N)*N+N",
    "(N+N+N)/N",
    "(N+N)*N+N",
    "N*N*N+N",
    "N*N-(N-N)",
    "N*N-(N+N)",
    "(N-N-N)*N",
    "N*N/N+N",
    "(N+N-N)*N",
    "N/(N/N-N)",
    "N*N-N*N"
  )

  def eval(str:String):Rational = {
    str match {
      case Bracket(part1, expr, part2) => eval(part1 + eval(expr) + part2)
      case Add(expr1, expr2) => eval(expr1) + eval(expr2)
      case Subtract(expr1, expr2) => eval(expr1) - eval(expr2)
      case Multiply(expr1, expr2) => eval(expr1) * eval(expr2)
      case Divide(expr1, expr2) =>  eval(expr1) / eval(expr2)
      case "" => new Rational(0, 1)
      case Rational(expr1, expr2) =>   new Rational(expr1.trim toInt, expr2.trim toInt)
      case _ => new Rational(str.trim toInt, 1)

    }
  }


  def calculate(template:String,numbers:List[Int])={
    val values=template.split('N')
    var expression=""
    for(i <- 0 to 3)  expression=expression+values(i) + numbers(i)
    if (values.length==5) expression=expression+values(4)
    (expression,template,eval(expression))
  }


  def cal24(input:List[Int])={
    var found = false
    for (template <- templates; list <- input.permutations ) {
      try {
        val (expression, tp, result) = calculate(template, list)
        if (result.numer == 24 && result.denom == 1) {
          println(input + ":" + tp + ":" + expression)
          found = true
        }
      } catch {
        case e:Throwable=>
      }
    }
    if (!found) {
      println(input+":"+"no result")
    }
  }

  def cal24once(input:List[Int])={
    var found = false
    for (template <- templates; list <- input.permutations if(!found)) {
      try {
        val (expression, tp, result) = calculate(template, list)
        if (result.numer == 24 && result.denom == 1) {
          println(input + ":" + tp + ":" + expression)
          found = true
        }
      } catch {
        case e:Throwable=>
      }
    }
    if (!found) {
      println(input+":"+"no result")
    }
  }
  println(cal24once(List(5,5,5,1)))
}

下面给出所有从1到10的四个数字有解的结果:

输入 模板 结果
List(1,1,1,8) (N+N+N)*N (1+1+1)*8
List(1,1,2,10) (N+N)*(N+N) (1+1)*(2+10)
List(1,1,2,6) (N+N)*N*N (1+1)*2*6
List(1,1,2,7) (N+N)*(N+N) (1+2)*(1+7)
List(1,1,2,8) (N+N)*N*N (1+2)*1*8
List(1,1,2,9) (N+N)*(N-N) (1+2)*(9-1)
List(1,1,3,10) (N-(N+N))*N (10-(1+1))*3
List(1,1,3,4) (N+N)*N*N (1+1)*3*4
List(1,1,3,5) (N+N)*(N+N) (1+3)*(1+5)
List(1,1,3,6) (N+N)*N*N (1+3)*1*6
List(1,1,3,7) (N+N)*N*N (1+7)*1*3
List(1,1,3,8) N*N-N+N 3*8-1+1
List(1,1,3,9) (N-N)*N*N (9-1)*1*3
List(1,1,4,10) N*(N+N)+N 10*(1+1)+4
List(1,1,4,4) (N+N+N)*N (1+1+4)*4
List(1,1,4,5) (N+N)*N*N (1+5)*1*4
List(1,1,4,6) N*N-N+N 4*6-1+1
List(1,1,4,7) (N-N)*N*N (7-1)*1*4
List(1,1,4,8) (N-N)*N*N (4-1)*1*8
List(1,1,4,9) (N-N)*(N-N) (1-4)*(1-9)
List(1,1,5,5) (N*N-N)*N (5*5-1)*1
List(1,1,5,6) (N-N)*N*N (5-1)*1*6
List(1,1,5,7) (N-N)*(N-N) (1-5)*(1-7)
List(1,1,5,8) (N-(N+N))*N (5-(1+1))*8
List(1,1,6,6) (N+N)*(N+N) (1+1)*(6+6)
List(1,1,6,8) N*N/(N+N) 6*8/(1+1)
List(1,1,6,9) N*(N+N)+N 9*(1+1)+6
List(1,1,7,10) N*(N+N)+N 7*(1+1)+10
List(1,1,8,8) N*(N+N)+N 8*(1+1)+8
List(1,2,2,10) (N+N)*N*N (2+10)*1*2
List(1,2,2,4) (N+N)*N*N (1+2)*2*4
List(1,2,2,5) (N+N)*N*N (1+5)*2*2
List(1,2,2,6) (N+N)*N*N (2+2)*1*6
List(1,2,2,7) (N-N)*N*N (7-1)*2*2
List(1,2,2,8) (N*N-N)*N (2*2-1)*8
List(1,2,2,9) (N+N+N)*N (1+2+9)*2
List(1,2,3,10) (N-N)*N*N (10-2)*1*3
List(1,2,3,3) (N+N)*N*N (1+3)*2*3
List(1,2,3,4) N*N*N*N 1*2*3*4
List(1,2,3,5) (N-N)*N*N (5-1)*2*3
List(1,2,3,6) (N-N)*N*N (3-1)*2*6
List(1,2,3,7) N*N+N+N 3*7+1+2
List(1,2,3,8) (N-N)*N*N (2-1)*3*8
List(1,2,3,9) (N+N)*N*N (3+9)*1*2
List(1,2,4,10) N*N+N*N 1*4+2*10
List(1,2,4,4) (N-N)*N*N (4-1)*2*4
List(1,2,4,5) (N-(N-N))*N (2-(1-5))*4
List(1,2,4,6) (N-N)*N*N (2-1)*4*6
List(1,2,4,7) (N-(N-N))*N (1-(2-7))*4
List(1,2,4,8) (N-N)*N*N (8-2)*1*4
List(1,2,4,9) (N-(N-N))*N (4-(1-9))*2
List(1,2,5,10) N*N-N+N 2*10-1+5
List(1,2,5,5) N*N-N+N 5*5-2+1
List(1,2,5,6) (N-(N-N))*N (1-(2-5))*6
List(1,2,5,7) (N+N)*N*N (5+7)*1*2
List(1,2,5,8) (N-N)*N*N (5-2)*1*8
List(1,2,5,9) N*N+N+N 2*9+1+5
List(1,2,6,10) (N/N-N)*N (10/2-1)*6
List(1,2,6,6) (N-N)*N*N (6-2)*1*6
List(1,2,6,7) (N-(N-N))*N (6-(1-7))*2
List(1,2,6,8) N*N/N/N 1*6/2/8
List(1,2,6,9) N*N+N*N 1*6+2*9
List(1,2,7,10) N*N+N*N 1*10+2*7
List(1,2,7,7) (N*N-N)/N (7*7-1)/2
List(1,2,7,8) N*N+N+N 2*8+1+7
List(1,2,7,9) N*N-N+N 2*9-1+7
List(1,2,8,10) N*(N-N)+N 2*(8-1)+10
List(1,2,8,8) N*N+N*N 1*8+2*8
List(1,2,8,9) N*N-N+N 2*8-1+9
List(1,3,10,10) N+N+N+N 1+3+10+10
List(1,3,3,10) (N-(N-N))*N (1-(3-10))*3
List(1,3,3,3) (N*N-N)*N (3*3-1)*3
List(1,3,3,4) (N-N)*N*N (3-1)*3*4
List(1,3,3,5) (N+N)*N*N (3+5)*1*3
List(1,3,3,6) (N-(N-N))*N (3-(1-6))*3
List(1,3,3,7) N*N+N*N 1*3+3*7
List(1,3,3,8) N*(N-N)+N 3*(8-1)+3
List(1,3,3,9) (N*N-N)*N (3*9-3)*1
List(1,3,4,10) N*(N-N)+N 10*(3-1)+4
List(1,3,4,4) (N+N)*N*N (4+4)*1*3
List(1,3,4,5) N*N+N+N 4*5+1+3
List(1,3,4,6) N/(N-N/N) 6/(1-3/4)
List(1,3,4,7) N*N-N+N 3*7-1+4
List(1,3,4,8) (N-(N-N))*N (1-(3-8))*4
List(1,3,4,9) N*N-N+N 3*9-4+1
List(1,3,5,10) N*N-N+N 3*5-1+10
List(1,3,5,6) N*N+N+N 3*6+1+5
List(1,3,5,7) (N+N)*(N-N) (1+5)*(7-3)
List(1,3,5,8) N*N+N+N 3*5+1+8
List(1,3,5,9) N*N+N*N 1*9+3*5
List(1,3,6,10) (N*N-N)*N (3*10-6)*1
List(1,3,6,6) N*N+N*N 1*6+3*6
List(1,3,6,7) N*N-N+N 3*6-1+7
List(1,3,6,8) (N-N)*N*N (6-3)*1*8
List(1,3,6,9) N*(N-N)+N 3*(6-1)+9
List(1,3,7,10) N*N-N+N 3*10-7+1
List(1,3,7,7) (N-N)*(N-N) (1-7)*(3-7)
List(1,3,7,8) N/(N-N/N) 3/(1-7/8)
List(1,3,7,9) (N+N)*N/N (1+7)*9/3
List(1,3,8,10) (N-N)*N/N (10-1)*8/3
List(1,3,8,8) N*(N-N)+N 8*(3-1)+8
List(1,3,8,9) N*N/N/N 1*8/3/9
List(1,3,9,10) (N+N)*N-N (1+10)*3-9
List(1,3,9,9) (N-N)*N/N (9-1)*9/3
List(1,4,10,10) N*N+N+N 1*4+10+10
List(1,4,4,10) (N-N)*N*N (10-4)*1*4
List(1,4,4,4) (N+N)*(N-N) (4+4)*(4-1)
List(1,4,4,5) N*N+N*N 1*4+4*5
List(1,4,4,6) N*(N-N)+N 4*(6-1)+4
List(1,4,4,7) (N*N-N)*N (4*7-4)*1
List(1,4,4,8) N*N+N*N 1*8+4*4
List(1,4,4,9) N*N-N+N 4*4-1+9
List(1,4,5,10) (N-(N-N))*N (1-(5-10))*4
List(1,4,5,5) N*N-N+N 4*5-1+5
List(1,4,5,6) N/(N-N/N) 4/(1-5/6)
List(1,4,5,7) N*N-N+N 4*7-5+1
List(1,4,5,8) N*(N-N)+N 4*(5-1)+8
List(1,4,5,9) N*(N-N)+N 5*(4-1)+9
List(1,4,6,10) (N-N)*N-N (4-1)*10-6
List(1,4,6,6) N*(N-N)+N 6*(4-1)+6
List(1,4,6,7) (N-(N-N))*N (1-(4-7))*6
List(1,4,6,8) (N-N)*N*N (8-4)*1*6
List(1,4,6,9) (N-(N+N))*N (9-(1+4))*6
List(1,4,7,7) (N+N)*(N-N) (1+7)*(7-4)
List(1,4,7,8) (N-N)*N*N (7-4)*1*8
List(1,4,7,9) (N-N)*(N-N) (1-9)*(4-7)
List(1,4,8,8) (N*N-N)*N (4*8-8)*1
List(1,4,8,9) N*N-N+N 4*8-9+1
List(1,4,9,10) N+N+N+N 1+4+9+10
List(1,5,10,10) N+N-(N-N) 5+10-(1-10)
List(1,5,5,10) (N-N)*N-N (10-5)*5-1
List(1,5,5,5) (N-N/N)*N (5-1/5)*5
List(1,5,5,6) (N+N)*N-N (1+5)*5-6
List(1,5,5,9) (N+N)*(N-N) (1+5)*(9-5)
List(1,5,6,10) (N+N)*(N-N) (1+5)*(10-6)
List(1,5,6,6) (N*N-N)*N (5*6-6)*1
List(1,5,6,7) N*N-N+N 5*6-7+1
List(1,5,6,8) (N-(N-N))*N (1-(5-8))*6
List(1,5,6,9) (N-N)*N*N (9-5)*1*6
List(1,5,7,10) (N/N+N)*N (7/5+1)*10
List(1,5,7,8) (N-(N-N))*N (1-(5-7))*8
List(1,5,7,9) (N-N)*(N-N) (1-7)*(5-9)
List(1,5,8,10) (N/N+N)*N (10/5+1)*8
List(1,5,8,8) (N-N)*N*N (8-5)*1*8
List(1,5,8,9) (N-N)*(N-N) (1-9)*(5-8)
List(1,5,9,10) N*N+N+N 1*5+9+10
List(1,5,9,9) N+N+N+N 1+5+9+9
List(1,6,6,10) (N-N)*N*N (10-6)*1*6
List(1,6,6,6) (N-N)*N-N (6-1)*6-6
List(1,6,6,8) N/(N-N/N) 6/(1-6/8)
List(1,6,6,9) (N-(N-N))*N (1-(6-9))*6
List(1,6,7,10) (N-(N-N))*N (1-(7-10))*6
List(1,6,7,9) (N+N)*(N-N) (1+7)*(9-6)
List(1,6,8,10) N*N+N+N 1*6+8+10
List(1,6,8,8) (N-(N-N))*N (1-(6-8))*8
List(1,6,8,9) (N-N)*N*N (9-6)*1*8
List(1,6,9,10) N+N-(N-N) 6+9-(1-10)
List(1,6,9,9) N*N+N+N 1*6+9+9
List(1,7,7,10) N*N+N+N 1*7+7+10
List(1,7,7,9) N+N+N+N 1+7+7+9
List(1,7,8,10) (N-N)*N*N (10-7)*1*8
List(1,7,8,8) N+N+N+N 1+7+8+8
List(1,7,8,9) N*N+N+N 1*7+8+9
List(1,7,9,10) (N-N)*(N-N) (1-9)*(7-10)
List(1,7,9,9) N+N-(N-N) 7+9-(1-9)
List(1,8,8,10) (N-(N-N))*N (1-(8-10))*8
List(1,8,8,8) N*N+N+N 1*8+8+8
List(1,8,8,9) N+N-(N-N) 8+8-(1-9)
List(2,2,10,10) N*N+N+N 2*2+10+10
List(2,2,2,10) N*N+N*N 2*2+2*10
List(2,2,2,3) (N+N)*N*N (2+2)*2*3
List(2,2,2,4) (N+N)*N*N (2+4)*2*2
List(2,2,2,5) (N+N*N)*N (2+2*5)*2
List(2,2,2,7) (N*N-N)*N (2*7-2)*2
List(2,2,2,8) (N-N)*N*N (8-2)*2*2
List(2,2,2,9) N*(N+N)+N 2*(2+9)+2
List(2,2,3,10) (N+N)*N-N (3+10)*2-2
List(2,2,3,3) (N+N)*N*N (3+3)*2*2
List(2,2,3,4) (N+N*N)*N (4+2*2)*3
List(2,2,3,5) (N*N-N)*N (2*5-2)*3
List(2,2,3,6) (N-N)*N*N (6-2)*2*3
List(2,2,3,7) (N/N+N)*N (2/2+7)*3
List(2,2,3,8) N*N-N+N 3*8-2+2
List(2,2,3,9) (N-N)*N*N (9-3)*2*2
List(2,2,4,10) (N-N)*N*N (10-4)*2*2
List(2,2,4,4) (N+N*N)*N (4+2*4)*2
List(2,2,4,5) (N-N)*N*N (5-2)*2*4
List(2,2,4,6) N*N-N+N 4*6-2+2
List(2,2,4,7) (N+N)*N-N (2+2)*7-4
List(2,2,4,8) N*N+N*N 2*4+2*8
List(2,2,4,9) N*N+N+N 2*9+2+4
List(2,2,5,10) (N-N)*(N-N) (2-5)*(2-10)
List(2,2,5,5) (N+N+N)*N (2+5+5)*2
List(2,2,5,6) (N+N)*(N-N) (2+6)*(5-2)
List(2,2,5,7) N*N+N*N 2*5+2*7
List(2,2,5,8) (N+N)*N-N (5+8)*2-2
List(2,2,5,9) (N-(N-N))*N (5-(2-9))*2
List(2,2,6,10) N*N-N+N 2*10-2+6
List(2,2,6,6) N*N+N*N 2*6+2*6
List(2,2,6,7) (N+N)*N-N (6+7)*2-2
List(2,2,6,8) N*N+N+N 2*8+2+6
List(2,2,6,9) (N*N-N)*N (2*9-6)*2
List(2,2,7,10) (N/N+N)*N (10/2+7)*2
List(2,2,7,7) (N-(N-N))*N (7-(2-7))*2
List(2,2,7,8) N*N+N+N 2*7+2+8
List(2,2,8,10) N*N-N+N 2*8-2+10
List(2,2,8,8) (N-N)*N/N (8-2)*8/2
List(2,2,8,9) N*N-N+N 2*9-2+8
List(2,2,9,10) N*(N-N)+N 2*(9-2)+10
List(2,3,10,10) N*(N-N)+N 2*(10-3)+10
List(2,3,3,10) (N/N+N)*N (10/2+3)*3
List(2,3,3,3) (N+N*N)*N (3+3*3)*2
List(2,3,3,5) (N*N-N)*N (3*5-3)*2
List(2,3,3,6) N*N+N*N 2*3+3*6
List(2,3,3,7) (N-N)*N*N (7-3)*2*3
List(2,3,3,8) (N-N)*N*N (3-2)*3*8
List(2,3,3,9) N*N+N+N 2*9+3+3
List(2,3,4,10) N*N+N+N 3*4+2+10
List(2,3,4,4) (N-N)*N*N (4-2)*3*4
List(2,3,4,5) (N-(N-N))*N (3-(2-5))*4
List(2,3,4,6) (N-N)*N*N (3-2)*4*6
List(2,3,4,7) (N-(N-N))*N (2-(3-7))*4
List(2,3,4,8) (N-N)*N*N (8-4)*2*3
List(2,3,4,9) (N+N)*N/N (3+9)*4/2
List(2,3,5,10) (N-(N-N))*N (5-(3-10))*2
List(2,3,5,5) N*N-N+N 5*5-3+2
List(2,3,5,6) (N-N)*N*N (5-3)*2*6
List(2,3,5,7) N*N-N+N 3*7-2+5
List(2,3,5,8) N*N+N+N 2*8+3+5
List(2,3,5,9) N*N-N+N 3*9-5+2
List(2,3,6,10) (N-N)*N*N (10-6)*2*3
List(2,3,6,6) (N*N-N)*N (3*6-6)*2
List(2,3,6,7) (N*N-N)*N (2*7-6)*3
List(2,3,6,8) N*N-N+N 3*6-2+8
List(2,3,6,9) N*N+N+N 2*6+3+9
List(2,3,7,10) N*N-N+N 2*10-3+7
List(2,3,7,7) N*N+N+N 2*7+3+7
List(2,3,7,8) (N-(N-N))*N (7-(3-8))*2
List(2,3,7,9) (N*N-N)*N (3*7-9)*2
List(2,3,8,10) N*N-N+N 3*10-8+2
List(2,3,8,8) (N*N-N)*N (2*8-8)*3
List(2,3,8,9) (N-N*N)*N (9-2*3)*8
List(2,3,9,10) (N*N-N)*N (2*9-10)*3
List(2,3,9,9) N*N-N+N 2*9-3+9
List(2,4,10,10) (N/N+N)*N (4/10+2)*10
List(2,4,4,10) N*N-N+N 4*4-2+10
List(2,4,4,4) N*N+N*N 2*4+4*4
List(2,4,4,5) (N*N-N)*N (2*5-4)*4
List(2,4,4,6) (N*N-N)*N (2*4-4)*6
List(2,4,4,7) (N-N)*N*N (7-4)*2*4
List(2,4,4,8) N*N+N+N 2*8+4+4
List(2,4,4,9) (N-N)*N-N (9-2)*4-4
List(2,4,5,10) N*N+N+N 2*5+4+10
List(2,4,5,5) N*(N+N)+N 2*(5+5)+4
List(2,4,5,6) N*N-N+N 4*5-2+6
List(2,4,5,7) (N+N)*N/N (5+7)*4/2
List(2,4,5,8) (N-N)*N*N (8-5)*2*4
List(2,4,5,9) (N-(N-N))*N (2-(5-9))*4
List(2,4,6,10) N*N+N+N 2*4+6+10
List(2,4,6,6) (N-N)*N*N (6-4)*2*6
List(2,4,6,7) N*N-N+N 4*7-6+2
List(2,4,6,8) N*N+N+N 2*6+4+8
List(2,4,6,9) (N-N)*N*N (9-6)*2*4
List(2,4,7,10) (N-N)*N*N (10-7)*2*4
List(2,4,7,7) (N+N)*N-N (7+7)*2-4
List(2,4,7,8) (N*N-N)*N (2*7-8)*4
List(2,4,7,9) N*N+N+N 2*4+7+9
List(2,4,8,10) N*N-N+N 2*10-4+8
List(2,4,8,8) N*N+N+N 2*4+8+8
List(2,4,8,9) (N-(N+N))*N (9-(2+4))*8
List(2,4,9,10) N*N-N+N 2*9-4+10
List(2,4,9,9) N+N+N+N 2+4+9+9
List(2,5,10,10) (N+N)*N/N (2+10)*10/5
List(2,5,5,10) (N-N/N)*N (5-2/10)*5
List(2,5,5,7) N*N+N+N 2*7+5+5
List(2,5,5,8) (N/N+N)*N (5/5+2)*8
List(2,5,5,9) N*N+N+N 2*5+5+9
List(2,5,6,10) (N/N+N)*N (10/5+2)*6
List(2,5,6,6) (N*N-N)*N (2*5-6)*6
List(2,5,6,7) (N-N)*N*N (7-5)*2*6
List(2,5,6,8) N*N-N+N 5*6-8+2
List(2,5,6,9) N+N*N/N 9+5*6/2
List(2,5,7,10) (N-(N-N))*N (7-(5-10))*2
List(2,5,7,7) N*N+N+N 2*5+7+7
List(2,5,7,8) (N*N-N)*N (2*5-7)*8
List(2,5,7,9) N*N-(N+N) 5*7-(2+9)
List(2,5,8,10) (N-N)*(N-N) (2-10)*(5-8)
List(2,5,8,8) (N+N*N)/N (8+5*8)/2
List(2,5,8,9) (N-(N-N))*N (8-(5-9))*2
List(2,5,9,10) N*N-N+N 2*10-5+9
List(2,6,10,10) N*N-N+N 2*10-6+10
List(2,6,6,10) N*N/N-N 6*10/2-6
List(2,6,6,6) N*N+N+N 2*6+6+6
List(2,6,6,7) (N-N/N)*N (7-6/2)*6
List(2,6,6,8) (N-N)*N*N (8-6)*2*6
List(2,6,6,9) (N*N-N)/N (6*9-6)/2
List(2,6,7,10) (N*N-N)*N (2*7-10)*6
List(2,6,7,8) (N-(N-N))*N (2-(6-7))*8
List(2,6,7,9) (N-N)*N*N (9-7)*2*6
List(2,6,8,10) (N-N)*N*N (10-8)*2*6
List(2,6,8,8) (N-N/N)*N (8-8/2)*6
List(2,6,8,9) (N*N-N)*N (2*6-9)*8
List(2,6,9,10) (N-N)*(N-N) (2-10)*(6-9)
List(2,6,9,9) (N-(N-N))*N (9-(6-9))*2
List(2,7,10,10) (N-N)*(N-N) (2-10)*(7-10)
List(2,7,7,10) (N/N+N)*N (10/7+2)*7
List(2,7,7,8) (N/N+N)*N (7/7+2)*8
List(2,7,8,8) (N-(N-N))*N (2-(7-8))*8
List(2,7,8,9) (N+N)*N-N (7+9)*2-8
List(2,7,9,10) (N-(N-N))*N (9-(7-10))*2
List(2,8,10,10) (N-(N-N))*N (10-(8-10))*2
List(2,8,8,10) N+N-(N-N) 8+8-(2-10)
List(2,8,8,8) (N/N+N)*N (8/8+2)*8
List(2,8,8,9) (N-(N-N))*N (2-(8-9))*8
List(2,8,9,10) (N-(N-N))*N (2-(9-10))*8
List(2,8,9,9) N+N-(N-N) 8+9-(2-9)
List(2,9,10,10) N+N+N/N 9+10+10/2
List(3,3,3,10) N*(N-N)+N 3*(10-3)+3
List(3,3,3,3) N*N*N-N 3*3*3-3
List(3,3,3,4) (N*N-N)*N (3*3-3)*4
List(3,3,3,5) N*N+N*N 3*3+3*5
List(3,3,3,6) N*N+N+N 3*6+3+3
List(3,3,3,7) (N/N+N)*N (3/3+7)*3
List(3,3,3,8) N*N-N+N 3*8-3+3
List(3,3,3,9) (N-N/N)*N (9-3/3)*3
List(3,3,4,4) N*N+N*N 3*4+3*4
List(3,3,4,5) (N-N)*N*N (5-3)*3*4
List(3,3,4,6) N*N-N+N 4*6-3+3
List(3,3,4,7) (N-(N-N))*N (4-(3-7))*3
List(3,3,4,8) (N-N)*N*N (4-3)*3*8
List(3,3,4,9) N*N+N+N 3*4+3+9
List(3,3,5,10) N*N+N+N 3*3+5+10
List(3,3,5,5) N*N-N/N 5*5-3/3
List(3,3,5,6) (N*N-N)*N (3*3-5)*6
List(3,3,5,7) (N*N-N)*N (3*5-7)*3
List(3,3,5,9) (N+N)*N/N (3+5)*9/3
List(3,3,6,10) (N*N-N)*N (3*6-10)*3
List(3,3,6,6) (N/N+N)*N (6/3+6)*3
List(3,3,6,7) N*N-N+N 3*7-3+6
List(3,3,6,8) (N*N-N)*N (3*3-6)*8
List(3,3,6,9) N*N-N+N 3*6-3+9
List(3,3,7,7) (N/N+N)*N (3/7+3)*7
List(3,3,7,8) N*N+N+N 3*3+7+8
List(3,3,7,9) (N-N)*(N-N) (3-7)*(3-9)
List(3,3,8,10) N+N+N+N 3+3+8+10
List(3,3,8,8) N/(N-N/N) 8/(3-8/3)
List(3,3,8,9) N*(N-N)+N 3*(8-3)+9
List(3,3,9,10) N*N-N+N 3*10-9+3
List(3,3,9,9) N*N-N/N 3*9-9/3
List(3,4,10,10) N*N-N+N 3*10-10+4
List(3,4,4,10) (N-N)*N-N (10-3)*4-4
List(3,4,4,4) (N+N)*N-N (3+4)*4-4
List(3,4,4,5) N*N+N+N 4*4+3+5
List(3,4,4,6) (N-N)*N*N (4-3)*4*6
List(3,4,4,7) (N-(N-N))*N (3-(4-7))*4
List(3,4,4,8) N*N-N+N 3*8-4+4
List(3,4,4,9) (N+N)*N/N (4+4)*9/3
List(3,4,5,10) N*(N-N)+N 10*(5-3)+4
List(3,4,5,5) N*N-N+N 5*5-4+3
List(3,4,5,6) (N-(N-N))*N (3-(4-5))*6
List(3,4,5,7) N*N-N+N 4*5-3+7
List(3,4,5,8) (N-N)*N*N (5-4)*3*8
List(3,4,5,9) (N*N-N)*N (3*5-9)*4
List(3,4,6,10) N*N-N+N 3*6-4+10
List(3,4,6,6) N*N+N+N 3*4+6+6
List(3,4,6,8) (N-N)*N*N (8-6)*3*4
List(3,4,6,9) (N-(N-N))*N (3-(6-9))*4
List(3,4,7,10) (N-(N-N))*N (3-(7-10))*4
List(3,4,7,7) N*N-N+N 3*7-4+7
List(3,4,7,8) N*(N-N)+N 4*(7-3)+8
List(3,4,7,9) N*N-N+N 3*9-7+4
List(3,4,8,10) (N-N)*N*N (10-8)*3*4
List(3,4,8,9) (N*N-N)*N (3*4-9)*8
List(3,4,9,9) N*(N-N)+N 3*(9-4)+9
List(3,5,10,10) (N-N/N)*N (10-10/5)*3
List(3,5,5,6) (N/N+N)*N (5/5+3)*6
List(3,5,5,7) (N/N+N)*N (5/5+7)*3
List(3,5,5,8) N*N-N+N 3*8-5+5
List(3,5,5,9) (N/N+N)*N (9/5+3)*5
List(3,5,6,10) (N/N+N)*N (10/5+6)*3
List(3,5,6,6) (N-(N-N))*N (3-(5-6))*6
List(3,5,6,7) (N-(N-N))*N (6-(5-7))*3
List(3,5,6,8) (N-N)*N*N (6-5)*3*8
List(3,5,6,9) N*N-N+N 5*6-9+3
List(3,5,7,10) (N-(N-N))*N (5-(7-10))*3
List(3,5,7,8) N*N-N+N 3*7-5+8
List(3,5,7,9) (N+N)*(N-N) (3+9)*(7-5)
List(3,5,8,8) N*(N-N)+N 8*(5-3)+8
List(3,5,8,9) N*N-N+N 3*9-8+5
List(3,5,9,10) N*(N-N)+N 3*(10-5)+9
List(3,5,9,9) (N-N)*(N-N) (3-9)*(5-9)
List(3,6,10,10) (N/N+N)*N (10/10+3)*6
List(3,6,6,10) (N-N)*N-N (6-3)*10-6
List(3,6,6,6) N*(N-N)+N 6*(6-3)+6
List(3,6,6,7) (N-(N-N))*N (3-(6-7))*6
List(3,6,6,8) N*N-N+N 3*8-6+6
List(3,6,6,9) N+N*N/N 6+6*9/3
List(3,6,7,10) N+N*N/N 10+6*7/3
List(3,6,7,7) (N-(N-N))*N (7-(6-7))*3
List(3,6,7,8) (N-N)*N*N (7-6)*3*8
List(3,6,7,9) N*N-N+N 3*7-6+9
List(3,6,8,10) (N-(N-N))*N (6-(8-10))*3
List(3,6,8,8) N+N*N/N 8+6*8/3
List(3,6,8,9) (N-(N-N))*N (3-(8-9))*6
List(3,6,9,10) (N-(N-N))*N (3-(9-10))*6
List(3,6,9,9) N*N-N+N 3*9-9+6
List(3,7,10,10) N+N-(N-N) 7+10-(3-10)
List(3,7,7,10) N*N-N+N 3*7-7+10
List(3,7,7,7) (N/N+N)*N (7/7+7)*3
List(3,7,7,8) N*N-N+N 3*8-7+7
List(3,7,7,9) (N-N/N)*N (9-7/7)*3
List(3,7,8,8) (N-N)*N*N (8-7)*3*8
List(3,7,8,9) (N-(N-N))*N (7-(8-9))*3
List(3,7,9,10) N*N-N+N 3*9-10+7
List(3,7,9,9) (N/N+N)*N (9/9+7)*3
List(3,8,10,10) N*N-N+N 3*8-10+10
List(3,8,8,10) (N*N-N)/N (8*10-8)/3
List(3,8,8,8) N*N-N+N 3*8-8+8
List(3,8,8,9) (N-N)*N*N (9-8)*3*8
List(3,8,9,10) (N-N)*N*N (10-9)*3*8
List(3,8,9,9) N*N-N+N 3*8-9+9
List(3,9,10,10) (N-N/N)*N (9-10/10)*3
List(3,9,9,10) (N-(N-N))*N (9-(10-9))*3
List(3,9,9,9) N+N-(N-N) 9+9-(3-9)
List(4,4,10,10) (N*N-N)/N (10*10-4)/4
List(4,4,4,10) (N*N-N)*N (4*4-10)*4
List(4,4,4,4) N*N+N+N 4*4+4+4
List(4,4,4,5) (N/N+N)*N (4/4+5)*4
List(4,4,4,6) N*N-N+N 4*6-4+4
List(4,4,4,7) (N+N)*(N-N) (4+4)*(7-4)
List(4,4,4,8) (N/N+N)*N (8/4+4)*4
List(4,4,4,9) N*(N-N)+N 4*(9-4)+4
List(4,4,5,10) N*(N-N)+N 4*(10-5)+4
List(4,4,5,5) (N-(N-N))*N (5-(4-5))*4
List(4,4,5,6) (N-N)*N*N (5-4)*4*6
List(4,4,5,7) (N-(N-N))*N (4-(5-7))*4
List(4,4,5,8) N*N-N+N 4*5-4+8
List(4,4,6,10) N*(N-N)+N 10*(6-4)+4
List(4,4,6,8) (N-(N-N))*N (4-(6-8))*4
List(4,4,6,9) N*N/N/N 4*4/6/9
List(4,4,7,10) (N+N)*(N-N) (4+4)*(10-7)
List(4,4,7,7) (N-N/N)*N (4-4/7)*7
List(4,4,7,8) N*N-N+N 4*7-8+4
List(4,4,7,9) (N-(N-N))*N (4-(7-9))*4
List(4,4,8,10) (N-(N-N))*N (4-(8-10))*4
List(4,4,8,8) N*(N-N)+N 4*(8-4)+8
List(4,4,8,9) N*N-(N+N) 4*9-(4+8)
List(4,5,10,10) N+N*N/N 4+10*10/5
List(4,5,5,10) N+N+N+N 4+5+5+10
List(4,5,5,5) N*N-N+N 5*5-5+4
List(4,5,5,6) N*N-N+N 4*6-5+5
List(4,5,5,7) (N-N/N)*N (7-5/5)*4
List(4,5,5,8) (N-N/N)*N (4-5/5)*8
List(4,5,5,9) N*N-N+N 4*5-5+9
List(4,5,6,10) N*N-N+N 4*5-6+10
List(4,5,6,6) (N-N)*N*N (6-5)*4*6
List(4,5,6,7) (N-(N-N))*N (5-(6-7))*4
List(4,5,6,8) (N-(N-N))*N (4-(6-5))*8
List(4,5,6,9) N+N+N+N 4+5+6+9
List(4,5,7,10) N*(N-N)+N 10*(7-5)+4
List(4,5,7,7) (N/N+N)*N (7/7+5)*4
List(4,5,7,8) (N-(N-N))*N (5-(7-8))*4
List(4,5,7,9) N*N-N+N 4*7-9+5
List(4,5,8,10) (N+N)*N/N (4+8)*10/5
List(4,5,8,8) (N/N+N)*N (8/8+5)*4
List(4,5,8,9) (N-(N-N))*N (5-(8-9))*4
List(4,5,9,10) (N-(N-N))*N (5-(9-10))*4
List(4,5,9,9) (N/N+N)*N (9/9+5)*4
List(4,6,10,10) N*N-N+N 4*6-10+10
List(4,6,6,10) (N+N)*N/N (6+10)*6/4
List(4,6,6,6) N*N-N+N 4*6-6+6
List(4,6,6,7) (N-N)*N*N (7-6)*4*6
List(4,6,6,8) N*N/(N-N) 6*8/(6-4)
List(4,6,6,9) N*(N-N)+N 9*(6-4)+6
List(4,6,7,10) N*N-N+N 4*7-10+6
List(4,6,7,7) N*N-N+N 4*6-7+7
List(4,6,7,8) (N-N)*N*N (8-7)*4*6
List(4,6,7,9) (N+N)*N/N (7+9)*6/4
List(4,6,8,10) N*(N-N)+N 4*(10-6)+8
List(4,6,8,8) N*N-N+N 4*6-8+8
List(4,6,8,9) (N-N)*N*N (9-8)*4*6
List(4,6,9,10) (N-N)*N*N (10-9)*4*6
List(4,6,9,9) N*N-N+N 4*6-9+9
List(4,7,10,10) (N-N/N)*N (7-10/10)*4
List(4,7,7,7) (N-N/N)*N (7-7/7)*4
List(4,7,7,8) (N-(N-N))*N (7-(8-7))*4
List(4,7,8,10) N+N*N/N 10+7*8/4
List(4,7,8,8) (N-(N-N))*N (4-(8-7))*8
List(4,7,8,9) (N-(N-N))*N (7-(9-8))*4
List(4,7,9,10) (N-(N-N))*N (7-(10-9))*4
List(4,7,9,9) (N-N/N)*N (7-9/9)*4
List(4,8,10,10) N+N-(N-N) 8+10-(4-10)
List(4,8,8,10) (N-(N-N))*N (8-(10-8))*4
List(4,8,8,8) N+N*N/N 8+8*8/4
List(4,8,8,9) (N-(N-N))*N (4-(9-8))*8
List(4,8,9,10) (N-(N-N))*N (4-(10-9))*8
List(4,8,9,9) (N-N/N)*N (4-9/9)*8
List(4,9,9,10) N+N-(N-N) 9+9-(4-10)
List(5,5,10,10) N*N-N/N 5*5-10/10
List(5,5,5,5) N*N-N/N 5*5-5/5
List(5,5,5,6) N*N-N+N 5*5-6+5
List(5,5,5,9) N+N+N+N 5+5+5+9
List(5,5,6,6) (N-(N-N))*N (5-(6-5))*6
List(5,5,6,7) N*N-N+N 5*5-7+6
List(5,5,6,8) N+N+N+N 5+5+6+8
List(5,5,7,10) (N+N)*N/N (5+7)*10/5
List(5,5,7,7) N*N-N/N 5*5-7/7
List(5,5,7,8) N*N-N+N 5*5-8+7
List(5,5,8,10) (N+N)*N/N (5+10)*8/5
List(5,5,8,8) N*N-N/N 5*5-8/8
List(5,5,8,9) N*N-N+N 5*5-9+8
List(5,5,9,10) N*N-N+N 5*5-10+9
List(5,5,9,9) N*N-N/N 5*5-9/9
List(5,6,10,10) (N+N)*N/N (10+10)*6/5
List(5,6,6,10) (N+N)*N/N (6+6)*10/5
List(5,6,6,6) (N-N/N)*N (5-6/6)*6
List(5,6,6,7) (N-(N-N))*N (5-(7-6))*6
List(5,6,6,8) N*(N-N)+N 6*(8-5)+6
List(5,6,6,9) N*N-N*N 6*9-5*6
List(5,6,7,7) (N-N/N)*N (5-7/7)*6
List(5,6,7,8) (N-(N-N))*N (5-(8-7))*6
List(5,6,7,9) N*(N-N)+N 9*(7-5)+6
List(5,6,8,10) N*N/N/N 5*6/10/8
List(5,6,8,8) (N-(N-N))*N (5-(8-6))*8
List(5,6,8,9) (N-(N-N))*N (5-(9-8))*6
List(5,6,9,10) (N-(N-N))*N (5-(10-9))*6
List(5,6,9,9) N*(N-N)+N 5*(9-6)+9
List(5,7,10,10) N+N*N/N 10+7*10/5
List(5,7,7,10) N*(N-N)+N 7*(7-5)+10
List(5,7,7,9) (N+N)*(N-N) (5+7)*(9-7)
List(5,7,8,10) (N+N)*(N-N) (5+7)*(10-8)
List(5,7,8,8) N*(N-N)+N 8*(7-5)+8
List(5,7,8,9) (N-(N-N))*N (5-(9-7))*8
List(5,7,9,10) N*(N-N)+N 5*(10-7)+9
List(5,8,8,10) (N-(N-N))*N (5-(10-8))*8
List(5,8,8,8) N*N-(N+N) 5*8-(8+8)
List(5,8,8,9) N*N/(N-N) 8*9/(8-5)
List(5,9,10,10) N+N-(N-N) 9+10-(5-10)
List(6,10,10,10) N+N-(N-N) 10+10-(6-10)
List(6,6,6,10) N*N-N*N 6*10-6*6
List(6,6,6,6) N+N+N+N 6+6+6+6
List(6,6,6,8) (N-(N-N))*N (6-(8-6))*6
List(6,6,6,9) N*(N-N)+N 6*(9-6)+6
List(6,6,7,10) N*(N-N)+N 6*(10-7)+6
List(6,6,7,9) (N-(N-N))*N (6-(9-7))*6
List(6,6,8,10) (N-(N-N))*N (6-(10-8))*6
List(6,6,8,8) N*N/(N-N) 6*8/(8-6)
List(6,6,8,9) (N-(N-N))*N (6-(9-6))*8
List(6,6,9,10) (N+N)*N/N (6+10)*9/6
List(6,7,10,10) (N-N)*N-N (10-7)*10-6
List(6,7,7,10) (N-(N-N))*N (7-(10-7))*6
List(6,7,8,10) (N-(N-N))*N (6-(10-7))*8
List(6,7,8,9) N*N/(N-N) 6*8/(9-7)
List(6,7,9,9) N*(N-N)+N 9*(9-7)+6
List(6,8,8,10) N*N/(N-N) 6*8/(10-8)
List(6,8,8,8) N*(N-N)+N 8*(8-6)+8
List(6,8,8,9) (N+N)*N/N (8+8)*9/6
List(6,8,9,10) N*(N-N)+N 9*(10-8)+6
List(6,8,9,9) N*N/(N-N) 8*9/(9-6)
List(6,9,9,10) N+N*N/N 9+9*10/6
List(7,7,9,10) N*(N-N)+N 7*(9-7)+10
List(7,8,10,10) N*(N-N)+N 7*(10-8)+10
List(7,8,8,10) N*N-N*N 8*10-7*8
List(7,8,8,9) N*(N-N)+N 8*(9-7)+8
List(7,8,9,10) N*N/(N-N) 8*9/(10-7)
List(8,8,8,10) N*(N-N)+N 8*(10-8)+8