VANO 发表于 2014-12-23 10:31:26

数字组合运算改进版

注: 这个程序由岳东晓编写,原贴链接 http://www.zhenzhubay.com/home.php?mod=space&uid=2&do=blog&id=25933



<h1>数字组合搜索 - Number combination search (c)YDX</h1>
输入数字 -- Enter integers to be combined<br>
<input name="nums" type="text" size="40" value=" 4 1 9 2" id="numsinput" style="background-repeat: no-repeat;"><br>
输入期待值 -- Enter target value:<br>
<input name="tgtinput" type="text" size="6" value="46" id="tgtinput" style=" background-repeat: no-repeat;"><br>
可选运算--- Optional calculations<br>
阶乘-Factorial <input type="checkbox" checked id="usefactorial"><br>
开方-Square root <input type="checkbox" id="usesqrt"><br>
点击开始(或停止)搜索 -- Click the button to start (or stop) calculation<br>
<input name="startbtn" type="button" value="Start" id="startbtn" style="width: 6em; height:6em"><br>


<h4><span id="userinput"></span></h4><br>

<h2> 发现解答 -- FOUND SOLUTIONS</h2>
<div id="compresult" style="overflow: auto; background-color: #efefef">
</div>

<h2> 部分尝试 -- ATTEMPTED</h2>
<div id="compprogress" style="height: 100px; overflow: scroll; background-color: #dddddd"></div>

<script>

(function(a){function b(){var b;d=new Worker('/zzw/combdoer.js');a("#compresult").html("");a("#compprogress").html("");b=a("#numsinput").val().match(/\d+/g);if(1>b.length||4<b.length)return alert("You must enter 1 to 4 numbers"),!1;var c=parseInt(a("#tgtinput").val());if(isNaN(c)||1>c)return alert("Target value must be a positive integer"),!1;a("#userinput").html("Input: ["+b.join()+"] --&gt;"+c);var e=[];a("#usefactorial").prop("checked")&&e.push("!");
a("#usesqrt").prop("checked")&&e.push("sqrt");d.postMessage({cmd:"find",nums:b,opts:{h:e},tgt:c});d.onmessage=function(b){b=b.data;switch(b.type){case "found":a("#compresult").prepend(b.tex+' <span class="mymath">'+b.tex+"="+b.val+" </span><br>");MathJax.Hub.Queue(["Typeset",MathJax.Hub,"compresult"]);break;case "tested":a("#compprogress").prepend(b.tex+" {"+b.val+"}<br>");break;case "done":h();break;case "alert":alert(b.msg)}};d.onerror=function(a){alert(["ERROR: Line ",a.i," in ",a.filename,
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ": ",a.message].join(""))};return!0}function h(){d&&d.terminate();a("#startbtn").val(c)}var d,c=["Start","Stop"];a(function(){a("#startbtn").click(function(){var d=a(this).val();d==c?b()&&a(this).val(c):d==c&&h()})})})(jQuery);


</script>

</div></div>
页: [1]
查看完整版本: 数字组合运算改进版