Skip to content

Instantly share code, notes, and snippets.

@bradmontgomery
Created May 9, 2011 14:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bradmontgomery/962589 to your computer and use it in GitHub Desktop.
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.
"""
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)
@dpritchett
Copy link

$ (curl -ks https://gist.github.com/raw/962589/17eca8aa3fb4b3231c3b5ca226ff9f03bfbb7093/paper.py ; echo -e "\n\nprint fold()") | python
1 folds, thickness = 0.01 inches
2 folds, thickness = 0.02 inches
3 folds, thickness = 0.03 inches
4 folds, thickness = 0.06 inches
5 folds, thickness = 0.13 inches
6 folds, thickness = 0.26 inches
7 folds, thickness = 0.51 inches
8 folds, thickness = 1.02 inches
9 folds, thickness = 2.05 inches
10 folds, thickness = 4.1 inches
11 folds, thickness = 8.19 inches
12 folds, thickness = 1.37 feet
13 folds, thickness = 2.73 feet
14 folds, thickness = 5.46 feet
15 folds, thickness = 10.92 feet
16 folds, thickness = 21.85 feet
17 folds, thickness = 43.69 feet
18 folds, thickness = 87.38 feet
19 folds, thickness = 174.76 feet
20 folds, thickness = 349.53 feet
21 folds, thickness = 699.05 feet
22 folds, thickness = 1398.1 feet
23 folds, thickness = 2796.2 feet
24 folds, thickness = 1.06 miles
25 folds, thickness = 2.12 miles
26 folds, thickness = 4.24 miles
27 folds, thickness = 8.47 miles
28 folds, thickness = 16.95 miles
29 folds, thickness = 33.89 miles
30 folds, thickness = 67.79 miles
31 folds, thickness = 135.57 miles
32 folds, thickness = 271.15 miles
33 folds, thickness = 542.29 miles
34 folds, thickness = 1084.59 miles
35 folds, thickness = 2169.18 miles
36 folds, thickness = 4338.35 miles
37 folds, thickness = 8676.7 miles
38 folds, thickness = 17353.4 miles
39 folds, thickness = 34706.81 miles
40 folds, thickness = 69413.61 miles
41 folds, thickness = 138827.23 miles
42 folds, thickness = 277654.45 miles
43 folds, thickness = 555308.9 miles
44 folds, thickness = 1110617.81 miles
45 folds, thickness = 2221235.61 miles
46 folds, thickness = 4442471.22 miles
47 folds, thickness = 8884942.45 miles
48 folds, thickness = 17769884.89 miles
49 folds, thickness = 35539769.79 miles
50 folds, thickness = 71079539.57 miles
None

@mdinstuhl
Copy link

That's great.

Now let's see you actually fold a piece of paper 50 times smart guy! ;-)

Seriously - VERY clever!

@bradmontgomery
Copy link
Author

bradmontgomery commented May 11, 2011 via email

@bjarkeeck
Copy link

1 fold = 0.01
2 fold = 0.02
Then 3 fold = 0.04 and not 0.03 right?

@bradmontgomery
Copy link
Author

@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

@bradmontgomery
Copy link
Author

Better yet, we should use millimeters, centimeters, kilometers instead an antiquated system of measurements ;)

@bradmontgomery
Copy link
Author

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

@rohithill
Copy link

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