Created
March 14, 2018 17:00
-
-
Save LexSong/8f3feb2d90bfad87e1128ae5fafd3c71 to your computer and use it in GitHub Desktop.
xkcd 1017
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
| from datetime import datetime, timedelta | |
| from math import exp, log | |
| from tqdm import trange | |
| from time import sleep | |
| # https://en.wikipedia.org/wiki/Age_of_the_universe | |
| # age of universe in years | |
| age_of_universe = 13.799e9 | |
| offset = 50 | |
| now = datetime.today() | |
| def get_past_date( delta_in_years ): | |
| if delta_in_years > 1e9: | |
| return "{:.2f} billion years ago".format( delta_in_years * 1e-9 ) | |
| if delta_in_years > 1e6: | |
| return "{:.2f} million years ago".format( delta_in_years * 1e-6 ) | |
| if delta_in_years > 50000: | |
| delta_in_years = round( delta_in_years / 5000 ) * 5000 | |
| return "{:,} years ago".format( delta_in_years ) | |
| if delta_in_years > 5000: | |
| bce_year = -round( ( now.year - delta_in_years ) / 100 ) * 100 | |
| return "{:,} BC".format( bce_year ) | |
| try: | |
| delta = timedelta( delta_in_years * 365.242199 ) | |
| return str( ( now - delta ).date() ) | |
| except: | |
| bce_year = -round( now.year - delta_in_years ) | |
| return "{:,} BC".format( bce_year ) | |
| def T(x): | |
| return exp( ( log(age_of_universe) - log(offset) ) * (x**3) + log(offset) ) - offset | |
| bar = trange( 10000, ascii=True ) | |
| for i in bar: | |
| sleep(0.02) | |
| p = i/10000 | |
| bar.set_description( get_past_date( T(p) ) ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment