XKCD progress indicator
You all read today’s xkcd and wanted to incorporate this formula into your programs straight away.
Here’s my Ruby implementation, if you would like a quick fix:
require 'date' class XkcdDate # Progress indicator formatted as a date, as in http://xkcd.com/1017/ def self.progress(amount, total) percent = (amount.to_f / total.to_f) years = Math::E ** (20.3444 * percent ** 3 + 3) - Math::E ** 3 Date.today - (years * 365.25) end end
It takes two arguments (amount and total, used to form the ratio) and returns a Ruby Date object, which you can format any way you like.
And examples of its uses, as in the comic:
>> [7.308, 31.12, 47.91, 70.33, 90.42, 100].each {|p| puts "#{p}: #{XkcdDate.progress(p, 100)}"} 7.308: 2011-12-18 31.12: 1995-02-15 47.91: 1844-01-17 70.33: -21765-11-11 90.42: -68315229-02-11 100: -13751308941-03-30 => [7.308, 31.12, 47.91, 70.33, 90.42, 100]
For those implementing it in other languages, when Randall says “percentage” he actually means “ratio”.