Created
April 16, 2020 08:41
-
-
Save abonzer/ec428c7c535b42e94ec5a6c779ab7c5b to your computer and use it in GitHub Desktop.
find all possible combinations of a set of options? how many possible combinations of answers are there
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title></title> | |
</head> | |
<body> | |
<div id="showdata"></div> | |
<script> | |
function binaryfun(no,base){ | |
var rem=0, result="",val=['A','B','C','D','E']; | |
if(no==0) | |
{ | |
result=result+val[0]; | |
} | |
while (no>0) { | |
rem=no%base; | |
no=Math.floor(no/base); | |
result=result+val[rem]; | |
} | |
for (var i=result.length;i<QuestionCount;i++) { | |
//alert(result.length); | |
result=result+val[0]; | |
//alert(result); | |
} | |
var splitstr = result.split(""); | |
var revstr = splitstr.reverse(); | |
var joinstr = revstr.join(); | |
return joinstr; | |
} | |
var QuestionCount=prompt("Enter No of Question ",0); | |
var base= prompt("Enter no of Option per Questoin(MAX 5) ",0); | |
var i,totalno; | |
totalno = Math.pow(base,QuestionCount); | |
var show= document.getElementById("showdata"); | |
show.innerHTML=show.innerHTML+'Total Combatation : '+ totalno+'<br/><br/>'; | |
for (i=0;i<totalno;i++) | |
{ | |
show.innerHTML=show.innerHTML+binaryfun(i,base)+"<BR/>"; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment