Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Backward in Time' xkcd

The popular comic xkcd posed this equation for converting time complete into a date:

Backward in Time

I've been trying to do the same in JavaScript, although I keep getting -Infinity. Here's the code:

var p = 5; // Percent Complete 
var today = new Date(); 
today = today.getTime(); 
var t;
t = (today) - (Math.pow(Math.E, (20.3444 * Math.pow(p,3))) -
Math.pow(Math.E,3));
document.write(t + " years");

Time will return a huge number (milliseconds), and I know that the equation isn't meant to deal with milliseconds - so how would one do an advanced date equation with JavaScript?

like image 862
Christopher Avatar asked Oct 06 '22 18:10

Christopher


1 Answers

You've made 3 mistakes:

  1. p should be a decimal between 0 and 1 to indicate the ratio of progress completed.
  2. The result is:
    T = (current date) - (a number in years)
    not
    T = (current date - a number) in years
    You need to first calculate (e^…-e^3) and then subtract that many years from t
  3. You've forgotten a +3 which was in the original formula

EDIT:

Here's some working code as a JSFiddle, although Javascript runs out of dates at around 75% completed

like image 133
Gareth Avatar answered Oct 10 '22 04:10

Gareth