非 bit 演算版 lotos() 再挑戦
bit 演算版をもとに当初の lotos() を見直してみたところかなり無駄な記述が含まれていたので書き直してみた。
function lotos(depth){ var coll=[],ceil; function getNum(){ return(function(x){ return x.substr(x.length-2,2) })("00"+ Math.ceil(Math.random()*ceil)); }; function isnotUniq(x){ for(i=0; (i<coll.length && !(isEx=(x==coll[i++])));); return isEx; } ceil=(function(x){for(i=c=0;i<x; c+= ++i);return c })(depth)*2+1; coll.push(getNum()); while( coll.length<depth ){ coll.push( (function(){ while(isnotUniq(x=getNum())); return x; })() ); } return coll; }; sx=read("5:minilot\n6:loto6\n"); if(sx<5 || sx>6){ println("bad arguments\n"); }else{ println(lotos(sx).sort().toString()); }
※ 20:48 2008/04/13 追記:typo 修正(fuction isnotUniq → function isnotUniq)