Created
July 29, 2012 21:17
-
-
Save NelsonMinar/3201872 to your computer and use it in GitHub Desktop.
Cantor pairing function
This file contains 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> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<title>Cantor pairing function</title> | |
<style> | |
td { min-width: 2em; text-align: right; } | |
</style> | |
</head> | |
<body> | |
<p>Mapping tuples (n, m) to the integers, see <a href="http://en.wikipedia.org/wiki/Cantor_pairing_function#Cantor_pairing_function">Cantor pairing function</a>. | |
<table id="cantor"></table> | |
<script> | |
function f(x, y) { | |
return ((x + y) * (x + y + 1)) / 2 + y; | |
} | |
for (var y = 0; y < 100; y++) { | |
var line = ['<tr>']; | |
for (var x = 0; x < 30; x++) { | |
line.push("<td>" + f(y, x) + "</td>"); | |
} | |
line.push("</tr>") | |
$("#cantor").append(line.join('')); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment