No.246 質問と回答 on Node.js Generator

//https://yukicoder.me/submissions/292157 を移植 const rl= […]

//https://yukicoder.me/submissions/292157 を移植 const rl= […]

  • タグ:
  • タグはありません
//https://yukicoder.me/submissions/292157 を移植
const rl=require("readline").createInterface(process.stdin,process.stdout);

const g=function*(){
	var numMin=1;
	var numMax=1000000001;
	for(;;){
		var chkNum=0|(numMin+numMax)/2;
		console.log("? %d",chkNum);
		if((yield rl.once("line",s=>g.next(s)))=="1") numMin=chkNum; else numMax=chkNum;
		if(numMin==numMax-1){
			console.log("! %d",numMin);
			break;
		}
	}
	process.exit();
}();
g.next();