Created
May 9, 2011 14:19
-
-
Save bradmontgomery/962589 to your computer and use it in GitHub Desktop.
Short python script to show that if you could fold a piece of paper in half 50 times, its thickness will be 3/4 the distance from the Earth to the Sun (71 million miles). Discovered on a very interesting Quora question.
This file contains 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
""" | |
Folding paper in half 50 times is 3/4 of the distance from earth to sun | |
From: | |
http://www.quora.com/What-are-some-of-the-most-mind-blowing-facts#answer_526501 | |
Thickness of a sheet of paper: 0.1 mm (~0.004 inches) | |
""" | |
def fold(num_folds=50, thickness=0.1): | |
"""Simulate folding a sheet of paper in half. | |
``num_folds`` is the number of times we'll fold the paper in half. | |
``thickness`` is the the thickness of a sheet of paper (in millimeters). | |
""" | |
for i in range(1, num_folds + 1): | |
thickness = thickness * 2 | |
if thickness >= 10000: | |
# convert to kilometers | |
t = thickness / 10000.0 | |
units = 'km' | |
elif thickness >= 1000: | |
# convert to meters | |
t = thickness / 1000.0 | |
units = 'm' | |
elif thickness >= 100: | |
# convert to centimeters | |
t = thickness / 100.0 | |
units = 'cm' | |
else: | |
# keep in millimeters | |
t = thickness | |
units = 'mm' | |
fmt_string = '{n} folds, thickness = {thickness:G} {units}' | |
print(fmt_string.format(n=i, thickness=t, units=units)) | |
if __name__ == "__main__": | |
n = input("\n\nHow many folds? ") | |
fold(n) |
That would be a neat trick! Totally wish I could :)
…On Wed, May 11, 2011 at 2:46 PM, mdinstuhl ***@***.*** wrote:
That's great.
Now let's see you actually fold a piece of paper 50 times smart guy! ;-)
Seriously - VERY clever!
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/962589
1 fold = 0.01
2 fold = 0.02
Then 3 fold = 0.04 and not 0.03 right?
@BjarkeCK I just noticed your comment. Yes, you're correct, but the default number of significant digits (the ndigits
parameter) causes a rounding error, there. A more precise example might be:
>>> fold(5, ndigits=3)
1 folds, thickness = 0.008 inches
2 folds, thickness = 0.016 inches
3 folds, thickness = 0.032 inches
4 folds, thickness = 0.064 inches
5 folds, thickness = 0.128 inches
Better yet, we should use millimeters, centimeters, kilometers instead an antiquated system of measurements ;)
Updates:
- Switched to metric units.
- Removed the
ndigits
parameter; using the:G
formatting option to round/format output - Can now be run interactively; e.g. with
python paper.py
Please correct your code. It must be:
if thickness >= 1000000:
# convert to kilometers
t = thickness / 1000000.0
units = 'km'
elif thickness >= 1000:
# convert to meters
t = thickness / 1000.0
units = 'm'
elif thickness >= 10:
# convert to centimeters
t = thickness / 10.0
units = 'cm'
else:
# keep in millimeters
t = thickness
units = 'mm'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's great.
Now let's see you actually fold a piece of paper 50 times smart guy! ;-)
Seriously - VERY clever!