You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe use some code like this to generate the answer
constops='-+*/='constnums='0123456789'constdesiredLength=8;functiongetOne(){letone;while(!one){one=tryOnce();}returnone;}functiontryOnce(){letcurrent='';while(current.length<desiredLength){constprev=current[current.length-1];constnextCanBeOp=nums.includes(prev);constnextCanBeNum=prev!=='0';letchoices;if(nextCanBeOp&&nextCanBeNum){choices=Math.random()<0.5 ? nums : ops;// 50/50 chance of choosing a number or operation next}elseif(nextCanBeOp){choices=ops;}elseif(nextCanBeNum){choices=nums;}else{return;}constindex=Math.floor(Math.random()*choices.length);constchar=choices[index];if(char==='='){constresult=eval(current);if(result>=0){// require the answer to be a single non-negative numberconstnerdle=current+'='+Math.floor(result).toString();if(nerdle.length===desiredLength){returnnerdle;}}returnundefined;}else{current+=char;}}}
The text was updated successfully, but these errors were encountered:
Like https://nerdlegame.com/
Maybe use some code like this to generate the answer
The text was updated successfully, but these errors were encountered: