Last active
June 25, 2019 20:01
-
-
Save zacharysyoung/e94bd931d833417972d5265e9a6e300f to your computer and use it in GitHub Desktop.
Prints a circumference of astronomical sizes in miles-feet-inches
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
# Inspired by: | |
# 'How many digits of pi do we really need?' | |
# (https://www.jpl.nasa.gov/edu/news/2016/3/16/how-many-decimals-of-pi-do-we-really-need/) | |
# | |
# I wanted to see for myself that the difference between 15 digits and 16 | |
# digits amounted to only half of an inch at the scale of Voyager 1's | |
# distance of ~12.5 billion miles | |
from decimal import Decimal, getcontext | |
getcontext().prec = 60 | |
def pi_to_nth_decimal(n=15): | |
# from https://oeis.org/A000796 | |
pi = (3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, | |
2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0, 2, 8, 8, 4, 1, 9, 7, 1, 6, | |
9, 3, 9, 9, 3, 7, 5, 1, 0, 5, 8, 2, 0, 9, 7, 4, 9, 4, 4, 5, 9, | |
2, 3, 0, 7, 8, 1, 6, 4, 0, 6, 2, 8, 6, 2, 0, 8, 9, 9, 8, 6, 2, | |
8, 0, 3, 4, 8, 2, 5, 3, 4, 2, 1, 1, 7, 0, 6, 7, 9, 8, 2, 1, 4) | |
return Decimal((0, pi[:n+1], -n)) | |
def astro_circf(radius_in_miles, pi_decimals=15): | |
pi = pi_to_nth_decimal(pi_decimals) | |
r_inches = radius_in_miles * 5280 * 12 | |
d = r_inches * 2 | |
circ = pi * Decimal(d) | |
return circ | |
def astro_dist(d): | |
inches = d % 12 | |
feet = ((d - inches) / 12) % 5280 | |
miles = (d - feet - inches) / (5280 * 12) | |
return '{:,} miles, {:,} feet, {:g} inches'.format( | |
int(miles), int(feet), inches) | |
def inches_to_angstroms(d): | |
return '{:g} angstroms'.format(d * Decimal(2.54e8)) | |
getcontext().prec = 20 | |
print('Circumference given V-ger1\'s distance of ~12.5 billion miles') | |
distance = 1.25e10 | |
dist_15 = astro_circf(distance, 15) | |
dist_16 = astro_circf(distance, 16) | |
print('15:', astro_dist(dist_15)) | |
print('16:', astro_dist(dist_16)) | |
print() | |
print('Difference between 15 and 16 digits is') | |
print(astro_dist(dist_16-dist_15)) | |
print() | |
getcontext().prec = 42 | |
print('The radius of the universe is about 46 billion light years') | |
distance = 4.6e10 * 5.88e12 # 5.88 trillion miles per light year | |
dist_39 = astro_circf(distance, 39) | |
dist_40 = astro_circf(distance, 40) | |
print('39:', astro_dist(dist_39)) | |
print('40:', astro_dist(dist_40)) | |
print() | |
print('Difference between 39 and 40 digits is') | |
print(astro_dist(dist_40-dist_39)) | |
print('or') | |
print(inches_to_angstroms(dist_40-dist_39)) | |
print() | |
# Circumference given V-ger1's distance of ~12.5 billion miles | |
# 15: 78,539,816,339 miles, 3,932 feet, 8.1120 inches | |
# 16: 78,539,816,339 miles, 3,932 feet, 8.4288 inches | |
# Difference between 15 and 16 digits is | |
# 0 miles, 0 feet, 0.3168 inches | |
# The radius of the universe is about 46 billion light years | |
# 39: 1,699,475,961,885,934,368,891,522 miles, 32 feet, 3.622581225019 inches | |
# 40: 1,699,475,961,885,934,368,891,522 miles, 32 feet, 3.622581225023 inches | |
# Difference between 39 and 40 digits is | |
# 0 miles, 0 feet, 4e-12 inches | |
# or | |
# 0.001016000000 angstroms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment