Skip to content

Instantly share code, notes, and snippets.

@AstraLuma
Created July 31, 2011 18:36
Show Gist options
  • Save AstraLuma/1117063 to your computer and use it in GitHub Desktop.
Save AstraLuma/1117063 to your computer and use it in GitHub Desktop.
Page to continuously factor the timestamp
<!DOCTYPE html>
<html>
<head><title>ufactor</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
function factor(n) {
if (n == 0 || n == 1) return [];
f = 2;
s = Math.sqrt(n);
while (n%f != 0) {
if (f > s) return [n];
f += 1;
}
return [f].concat(factor(Math.floor(n/f)));
}
function now() {
return Math.floor((new Date()).getTime() / 1000);
}
$(function () {
setInterval(function () {
var time = now();
var factors = factor(time);
$('#time').text(time);
if (factors.length == 0) {
$('#factor').text("Mathematically ambiguous");
} else if (factors.length == 1) {
$('#factor').text("prime");
} else {
/*var powers = [[factors[0], 1]];
for (var n in factors.slice(1)) {
if (n == powers[powers.length-1][0]) {
powers[powers.length-1][1] += 1;
} else {
powers.push([n, 1]);
}
}
function fmt(b,n) {
if (n == 1) {
return new String(b);
} else {
return b+'^'+n;
}
}
var rv = [];
for (var pow in powers) {
rv.push(fmt(pow[0], pow[1]));
}*/
$('#factor').text(factors.join(' * '));
}
}, 1000);
});
</script>
</head>
<body>
<span id="time">0</span> = <span id="factor"></span>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment