Last active
September 24, 2022 18:21
-
-
Save travc/d1998657c08b1d4c74073b7647fbf883 to your computer and use it in GitHub Desktop.
html+javascript to do flat permutations
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> | |
<title> flat permutation </title> | |
<script> | |
function myMain(event){ | |
document.getElementById("topbox").innerHTML = "<h1> HELLO </h1>"; | |
document.getElementById('answertext').addEventListener('keydown', (ev) => { | |
if (ev.key === 'Enter') { | |
update_perm(parseInt(ev.target.value)); | |
} | |
}); | |
} | |
function update_perm(val){ | |
console.log("Foo"); | |
const a = Array.apply(null, Array(val)).map(function (_, i){return i;}); | |
const b = Array(); | |
while( a.length > 0 ){ | |
var idx = Math.floor(Math.random()*a.length); | |
b.push(a[idx]); | |
a.splice(idx,1); | |
} | |
document.getElementById("topbox").innerHTML = "<h1>"+b.toString()+"</h1>"; | |
} | |
// Tell the page to run myMain after the page (HTML) is loaded | |
document.addEventListener('DOMContentLoaded', myMain, false); | |
</script> | |
</head> | |
<body> | |
<div id="topbox"></div> | |
<div id="shortcuts"> | |
<button onclick="update_perm(2)">2</button> | |
<button onclick="update_perm(3)">3</button> | |
<button onclick="update_perm(4)">4</button> | |
<button onclick="update_perm(5)">5</button> | |
<button onclick="update_perm(6)">6</button> | |
<button onclick="update_perm(7)">7</button> | |
</div> | |
<br> | |
<div id="answerbox"> | |
<input id="answertext" type="text" id="ans"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment