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8/(8-5)U6666,6+6+6+6 6x6-6-6U6668,(8-6)x(6+6) 6x(6+6-8)U6669,6x(9-6)+6 6x6x6/9U6679,(9-7)x(6+6) 6x(7+6-9)U6688,8x6/(8-6)U6689,8x(6+6-9) 9x(8-6)+6U6789,8x6/(9-7)U6799,9x(7+9)/6 6+9x(9-7) 7x6-9-9U6888,8x(8-6)+8U6889,9x(8+8)/6 9x8-6x8U6899,8x(9+9)/6 8x9/(9-6)U7889,8x(9-7)+8U";
var solutions;
function init()
{ input=new Array();
  for (var i=0;i<4;i++)
  {  nums[i]=(Math.ceil(Math.random()*9)); 
     document.getElementById("num"+i.toString()+"p").replaceChild(document.createTextNode(nums[i].toString()),document.getElementById("num"+i.toString()+"p").firstChild); }
  var nums_sort=nums.slice(0);
  nums_sort.sort();
  solutions="";
  
  if (all_solutions.indexOf(nums_sort.join("")+",")>=0)  
  { solutions=all_solutions.slice(all_solutions.indexOf(nums_sort.join("")+",")+5,all_solutions.indexOf("U",all_solutions.indexOf(nums_sort.join("")+",")));
    solutions=solutions.replace(/ /g,"\n");  }
   update(); }

function press(ref)
{ switch(ref)
  { case 21: input.pop(); update();break;
    case 22: input=new Array(); update();break;
    case 23: if (solutions=="") {alert("Right!");init();} else  if (!confirm("Wrong! Try again?"))  {alert("All solutions:\n"+solutions); init(); }break;    ;
    case 24: init(); break;
    case 25: if (solutions=="") alert ("No solutions!"); else alert(solutions); init(); break;    
    default: input.push(ref);update(); }
    
   }

function bcount(tcstring)
{ var c=0;
  for (var i=0;i<tcstring.length;i++)
    c+=(tcstring.charAt(i)=="(")-(tcstring.charAt(i)==")");
  return c; }

function update()
{ document.getElementById("c").disabled=(input.length==0);
  document.getElementById("ce").disabled=(input.length==0); 
  var full_term=true;
  if (input.length)
    full_term=(input[input.length-1]>10);
  document.getElementById("num0").disabled=!full_term;
  document.getElementById("num1").disabled=!full_term;
  document.getElementById("num2").disabled=!full_term;
  document.getElementById("num3").disabled=!full_term;
  document.getElementById("num0p").style.textDecoration="none";
  document.getElementById("num1p").style.textDecoration="none";
  document.getElementById("num2p").style.textDecoration="none";
  document.getElementById("num3p").style.textDecoration="none";
  document.getElementById("add").disabled=full_term;
  document.getElementById("sub").disabled=full_term;
  document.getElementById("mul").disabled=full_term;
  document.getElementById("div").disabled=full_term;
  document.getElementById("brop").disabled=!full_term;
  document.getElementById("brcl").disabled=full_term;
  var output="";
  for (var i=0;i<input.length;i++)
    switch(input[i])
    { case 11:output+="+"; break;
      case 12:output+="-"; break;   
      case 13:output+="x"; break;   
      case 14:output+="/"; break;   
      case 15:output+="("; break;   
      case -15:output+=")"; break;  
      default: output+=nums[input[i]];}
   if (output.length==0)
  document.getElementById("label").replaceChild(document.createTextNode("_"), document.getElementById("label").firstChild);
   
   else
    document.getElementById("label").replaceChild(document.createTextNode(output), document.getElementById("label").firstChild);
  
  if (bcount(output)==0)
    document.getElementById("brcl").disabled=true;
  var finish=4;
  for (var i=0;i<input.length;i++)
    if (input[i]>=0 && input[i]<5)
    { finish--;
      document.getElementById("num"+input[i].toString()).disabled=true; 
      document.getElementById("num"+input[i].toString()+"p").style.textDecoration="line-through";
  } 
 if (finish==0)
 { while(bcount(output)>0)
     output+=")"; 
   document.getElementById("label").replaceChild(document.createTextNode(output+"="+(Math.round(eval(output.replace(/x/g,"*"))*1000)/1000).toString()), document.getElementById("label").firstChild);
   if (Math.round(eval(output.replace(/x/g,"*"))*1000)/1000==24)
   { if(confirm("Right! Show all solutions?"))
       alert("All solutions:\n"+solutions);
     init(); }
   else
      if (confirm("Wrong! Try again?"))
        press(22);
      else
      { if (solutions=="")  
          alert("There were no solutions!");
        else
          alert("All solutions:\n"+solutions);
        init(); } } }

function solve()
{ for (var i=0;i<4;i++)
  nums[i]=document.getElementById("num"+i.toString()).value;
  var nums_sort=nums.slice(0);
  nums_sort.sort();
  solutions="";
  
  if (all_solutions.indexOf(nums_sort.join("")+",")>=0) 
    alert("All solutions:\n"+all_solutions.slice(all_solutions.indexOf(nums_sort.join("")+",")+5,all_solutions.indexOf("U",all_solutions.indexOf(nums_sort.join("")+","))).replace(/ /g,"\n"));
  else
    alert("No solutions!");
     } 