Have you heard about the myth that [if you fold a paper enough times, you can reach the moon with it](http://scienceblogs.com/startswithabang/2009/08/31/paper-folding-to-the-moon/)? Sure you have, but exactly how many? Maybe it's time to write a program to figure it out.

You know that a piece of paper has a thickness of `0.0001m`. Given `distance` in units of meters, calculate how many times you have to fold the paper to make the paper reach this distance.  
(If you're not familiar with the concept of folding a paper: Each fold doubles its total thickness.)

Note: Of course you can't do half a fold. You should know what this means ;P

Also, if somebody is giving you a negative distance, it's clearly bogus and you should yell at them by returning `null` (or whatever equivalent in your language. In Shell please return `None`).

Difficulty: introductory

Starter code:

def fold_to(distance):
	

Solutions:
def fold_to(distance, thickness=0.0001, folds=0):
    if distance < 0:
        return
    
    while thickness < distance:
        thickness *= 2
        folds += 1
    
    return folds

import math
def fold_to(d):
    if d<0:
        return None
    if d<0.0001:
        return 0
    return math.ceil(math.log(d/0.0001,2))

def fold_to(distance):
    if distance < 0: return None
    i = 0
    while (0.0001) * 2 ** i < distance:
        i += 1
    return i

def fold_to(distance):
    if distance >= 0:
        return int(distance * 10000).bit_length()

def fold_to(distance):
    const = 0.0001
    if distance < 0:
        return None
    elif distance < const:
        return 0
    fold =  0
    while distance > const * 2**fold:
        fold += 1
    return fold

from math import ceil, log2

def fold_to(distance, thickness=1e-4):
    if distance >= 0:
        return distance >= thickness and ceil(log2(distance / thickness))

from math import log
def fold_to(d):
    if d == 0:
        return 0
    if d>0:
        a = (log(d/0.0001)//log(2)) + 1
        return max(a,0)

def fold_to(distance):
    fold, thickness = 0, 0.0001;
    if distance < 0: return(None)
    while thickness <= distance:
        thickness *= 2
        fold += 1
    return(fold)

def fold_to(d):
  if d >= 0: return next(i for i in range(100) if 1e-4*2**i >= d)

def fold_to(distance):
  if distance >= 0: return next(i for i in __import__('itertools').count() if 1e-4*2**i >= distance)

from math import log,ceil
def fold_to(d):
    if d>=0: return d and max(0, ceil(log(10000*d, 2)))


from math import log2, ceil
from decimal import Decimal

paper_thickness_meters = Decimal('0.0001')

def fold_to(distance):
    if distance < 0:
        return None
    elif distance < paper_thickness_meters:
        return 0
    layers = Decimal(str(distance)) / paper_thickness_meters
    return ceil(log2(layers))

from math import log, ceil

def fold_to(d):
    return None if d < 0 else 0 if d < 0.0001 else ceil(log(d/0.0001, 2))

from math import log, ceil

def fold_to(distance, thickness = 0.0001):
    return None if distance < 0 else 0 if distance <= thickness else ceil(log(distance/thickness, 2))

def fold_to(distance):
    thickness=0.0001
    i=0
    if(distance>0):
      while(distance>thickness):
          thickness*=2
          i+=1
      return i
    else:
        if(distance==0):
            return 0
        else:
           return None

from math import log2, ceil


def fold_to(distance):
    return None if distance < 0 else ceil(log2(max(distance * 1e4, 1)))

from math import log, ceil; fold_to=lambda d: None if d<0 else 0 if d<0.0001 else ceil(log(d*10000,2))

def fold_to(distance):
    print(distance)
    if distance == None:
        return 0
    if distance < 0:
        return None
    if distance == 0.0:
        return 0
    res = .0001
    folds = 0
    while res < distance:
        res *= 2
        folds += 1
    return folds


def fold_to(distance):
    thickness = 0.0001
    if distance < 0:
        return None;
    else :
        i = 0;
        while thickness<distance:
            thickness = thickness *2;
            i = i +1;
        return i;

def fold_to(distance):
    #your code here
    folds = 0
    thickness = 0.0001
    total = 0
    
    if distance >= 0:
        while thickness < distance:
            thickness *= 2
            folds += 1
    
    else:
        return None
    
    return folds

import math

def fold_to(distance):
    if distance < 0:
        return None
    elif distance < 0.0001:
        return 0
    else:
        n = (math.log((distance/0.0001), 10)/math.log(2, 10)) + 1
        return math.floor(n)

def fold_to(distance):
    if distance < 0:
        return None
    thickness = 0.0001
    idx = 0
    while thickness < distance:
        thickness *= 2
        idx +=1 
    return idx

def fold_to(distance):
    position = 0.0001
    folds = 0
    while position<distance:
        position = position*2
        folds +=1
        
    if distance<0:
        return None
    else:
        return folds

fold_to=lambda distance:None if distance <0 else 0 if distance==0 or __import__('math').log(distance*10000,2)<0 else int(__import__('math').log(distance*10000,2))+1

import math
def fold_to(d):
    if d<0:
        return None
    if d<.0001:
        return 0
    return math.ceil(math.log(10000*d)/math.log(2))

def fold_to(distance):
    paperThickness = .0001
    folds = 0
    if distance < 0:
        return None
    while paperThickness < distance:
        paperThickness *=2
        folds+=1
    return folds

import unittest


def fold_to(distance):
    folding_count = 0
    meter_of_paper = 0.0001

    while meter_of_paper <= distance:
        folding_count += 1
        meter_of_paper = meter_of_paper * 2

    return folding_count if distance >= 0 else None
    
    
class TestFoldTo(unittest.TestCase):
    def test_fold_to_should_return_none_whne_given_distance_is_negative_one(self):
        distance = -1
        actual = fold_to(distance)
        self.assertEqual(actual, None)

    def test_fold_to(self):
        distance = 384000000
        actual = fold_to(distance)
        self.assertEqual(actual, 42)


def fold_to(distance):
    paper_thick = 0.0001
    folding=0
    if distance < 0:
        return None
    elif distance == 0:
        return 0
    while distance > paper_thick:
        paper_thick = paper_thick*2
        folding+=1
    return folding


def fold_to(distance):
    if distance < 0:
        return None
    elif distance == 0:
        return 0
    else:
        folds = 0
        thickness = 0.0001
        while thickness <= distance:
            thickness *= 2
            folds += 1
    return folds
    #your code here


def fold_to(distance):
    a = 0
    n = 0.0001
    if distance < 0:
        return None
    while n < distance:
        n *= 2
        a += 1
    return a

THICKNESS = 0.0001
def fold_to(distance):
    if distance < 0:
        return None
    current_thick = THICKNESS
    time = 0
    while current_thick < distance:
        current_thick += current_thick
        time += 1
    return time

def fold_to(distance):
    if distance < 0: return None
    length = 0.0001
    count= 0
    while length <= distance:
        length *= 2
        count += 1
    return count

def fold_to(distance):
    if distance < 0: return None
    length, count = 0.0001, 0
    while length <= distance:
        length *= 2
        count += 1
    return count

import math
def fold_to(distance):
    return (math.ceil(math.log2(distance/0.0001)) if distance >=0.0001 else None if distance < 0 else 0)

def fold_to(distance):
    if distance < 0:
        return None
    else:
        counter = 0
        i = 0.0001
        while i <= distance:
            i *= 2
            counter += 1
        return counter

def fold_to(distance):
    #your code here
    import math
    thick = 0.0001
    if distance<0:
        return None
    elif distance<thick:
        return 0
    else:
        return math.ceil(math.log2(distance/thick))


def fold_to(distance):
    thicc = 0.0001
    counter = 0
    if distance >= 0:
        while thicc < distance:
            thicc = thicc * 2
            counter += 1
    else:
        counter = None
    return counter

def fold_to(distance):
    folds = 0
    thickness = 0.0001
    if distance < 0:
        return
    while thickness < distance:
        thickness *= 2
        folds += 1
    return folds

from math import log, ceil
def fold_to(d):
    if d < 0: 
        return None
    if d == 0:
        return 0
    return max(0, ceil(log(d / 0.0001, 2)))

def fold_to(distance):
    d = 0.0001
    c = 0
    if distance < 0:
        return None
    while d < distance:
        d = d * 2
        c += 1
    return c

import math
def fold_to(distance):
    if distance < 0: return None
    su = 0.0001
    fold = 0
    while su < distance:
        su*=2
        fold+=1
    return fold

def fold_to(distance):
    if distance < 0:
        return
    
    i = 0
    l = 0.0001
    while l < distance:
        l = l * 2
        i = i + 1
    return i

import math
def fold_to(distance):
    thickness = 0.0001
    if distance == 0: 
        return 0
    elif distance > 0:
        return max(math.ceil(math.log(distance,2)-math.log(thickness,2)),0)
    else:
        return None

def fold_to(distance):
    if distance < 0:
        return None
    i = .0001
    count = 0
    if distance == 0:
        return 0
    while distance > i:
        distance = distance / 2
        count += 1
    return count

import math
def fold_to(distance):
    if distance<0:
        return None
    if distance < 0.0001:
        return 0
    return int(math.ceil(math.log(distance/0.0001,2)))

def fold_to(distance):
    p = 0.0001
    
    
    if distance < 0:
        return None
    
    print(p)
    if p >= distance:
        return 0
    

    
    count = 0
    
    print(p)
    
    while p < distance:
        p += p
        count += 1
    
    return count

def fold_to(distance):
    paper=0.0001
    i=0
    if distance<0:return None
    while paper<distance:
        i+=1
        paper*=2
    return i

from math import log2

def fold_to(distance):
    if distance < 0:
        return None
    elif distance == 0:
        return 0
    return max(int(log2(distance / 0.0001)) + 1, 0)

def fold_to(distance):
    if distance >= 0:
        counter = 0
        t = 0.0001
        while t < distance:
            t *= 2
            counter += 1
        return counter

from math import log2, ceil

def fold_to(distance):
    thickness = 0.0001
    return None if distance < 0 else 0 if distance < thickness else ceil(log2(distance/thickness))

def fold_to(distance):
    thickness = 0.0001
    if distance < 0:
        return None
    i = 0
    while thickness < distance:
        thickness *= 2
        i += 1
    return i

from math import log2,ceil

def fold_to(distance):
    if distance < 0 : return None
    elif distance==0 : return 0
    return max(0,ceil(log2(distance*10000)))

def fold_to(d):
    if d<0:
        return None
    r = 0.0001
    x=0
    while r < d:
        x += 1
        r *=2
    return x

def fold_to(d):
    if d >= 0: return next(i for i in range(88) if 1e-4*2**i >= d)

def fold_to(distance):
    if distance<0:
        return None
    for i in range(0,10000):
        if (2**i)*0.0001>=distance:
            return i


def fold_to(distance):
    count=0
    if distance < 0:
        return None
    thickness=0.0001
    if distance < thickness:
        return 0
    while thickness < distance:
        thickness *= 2
        count += 1
    return count


def fold_to(distance):
    
    if distance < 0 :
        return None
    
    a = 0
    
    while distance >= .0001 :
        distance /= 2
        a += 1
    
    return a


import math
def fold_to(distance):
    if distance < 0:
        return None
    fold = math.ceil(math.log(distance/0.0001, 2)) if distance else 0
    return fold if fold > 0 else 0


import math

def fold_to(distance):
    if distance <0:
        return None
    if distance <0.0001:
        return 0
    else:
        return math.ceil((math.log(distance/0.0001))/(math.log(2)))
    


def fold_to(distance):
    if distance <0 : return None
    d = 0.0001
    n = 0
    while(d<distance) : 
        d *=2
        n +=1
    return n

def fold_to(distance):
    if distance < 0.0:
        return None
    thickness = 0.0001
    count = 0
    while thickness < distance:
        thickness = thickness*2
        count+=1
    return count
    #end


def fold_to(distance):
    if distance < 0:
        return None
    if distance < 0.0001:
        return 0
    counter = 0
    while distance > 0.0001:
        distance /= 2
        counter += 1
    return counter


def fold_to(distance):
    if distance<0: return None
    thickness = 0.0001
    n = 0
    while thickness*(2**n) < distance:
        #print(n, 2**n, thickness*(2**n))
        n+=1
    return n

def fold_to(distance):
    epais = 0.0001
    compte=0
    if distance<0:
        return None
    else:
        while epais<distance:
            epais=epais*2
            compte += 1
        return compte

def fold_to(distance):
    folds = 0
    thickness = 0.0001
    if distance < 0:
        return None
    else:
        while thickness < distance:
            thickness *= 2
            folds += 1
        return folds

def fold_to(distance):   
    thick = 0.0001

    if distance < 0:
        return None

    elif thick > distance:
        return 0

    else:
        counter = 0
        while thick < distance:
            thick = thick * 2
            counter += 1

    return counter

def fold_to(distance):
    fold=0.0001
    
    if distance <=-1:
        return None
    elif distance < fold:
        return 0
    i=0
    while fold<=distance:
        fold=fold*2
        i+=1
    return i

def fold_to(distance):
    x = 0.0001
    count = 0
    if distance > x:
        while(x < distance):
            x += x
            count += 1
        return count
    elif distance<0:
        return None
    return 0

import math
def fold_to(distance):
    return math.ceil(math.log((distance/0.0001),2)) if distance>0.0001 else None if distance<0 else 0

from math import log2, ceil
def fold_to(distance):
    if 0 > distance: return None
    if distance <= 0.0001: return 0
    return ceil(log2(10000*distance))

def fold_to(distance):
  if (distance < 0): return None
  folds = 0
  while (0.0001 < distance): folds += 1; distance /= 2
  return folds

def fold_to(distance):
    if distance < 0:
        return None
        
    thiccness = .0001
    folds = 0
    
    while thiccness < distance:
        thiccness = thiccness * 2
        folds = folds + 1
        
    return folds
        


def fold_to(distance):
    i = 0
    while distance > 0.00010:
        distance =distance / 2
        i += 1
        
    return i if distance >=0 else None

def fold_to(distance):
    thickness = 0.0001
    folds = 0
    
    if distance < 0:
        return None
        
    elif distance < thickness:
        return 0
        
    else:
        while thickness < distance:
            thickness = thickness * 2
            folds = folds + 1
        
            if thickness >= distance:
                return int(folds)

def fold_to(distance):
    if distance < 0:
        return None
    n = 0.0001
    cnt = 0
    while n < distance:
        n = n*2
        cnt += 1
    return cnt

def fold_to(distance):
    if distance >= 0:
        thicc = 0.0001
        count = 0
        while thicc < distance:
            thicc = thicc * 2
            count += 1 
        return count
    else: return None 

def fold_to(distance):
    #your code here
    n = 0
    results = 0
    if 0.0001 < distance:
        while results < distance:
            n+=1
            results = 0.0001*(2**n) 
        return n
    if distance < 0:
        return None
    if 0.0001 > distance:
        return 0
        



from math import ceil, log2
def fold_to(distance):
    thickness = 0.0001
    if distance < 0:
        return None
    if distance <= thickness:
        return 0
    return ceil(log2(distance/thickness))

def fold_to(distance):
    from math import log, ceil
    distance = float(distance)
    paper = 0.0001
    if distance >= paper:
        return ceil(log(distance/paper, 2))
    else:
        if distance >= 0:
            return 0
        else:
            return None

from math import ceil, log2

def fold_to(distance):
    if distance < 0:
      return None
    if not distance:
      return 0
    return max(0, ceil(log2(distance / 0.0001)))

from math import *
def fold_to(d):
    if d < 0 : return None
    elif floor(d*10000) == 0: return 0
    else : return ceil(log(d*10000, 2))

def fold_to(distance):
    p = 0.0001
    n = 0
    while p <= distance:
         p = p * 2
         n += 1
    if distance < 0:
       return None
    else:
       return n
    #your code here


from math import *
def fold_to(distance):
    if distance < 0: return None
    elif distance < .0001: return 0
    else: return ceil(log2(distance/.0001))

def fold_to(distance):
    count = 0
    p_thickness = 0.0001
    if distance >= 0:
        while p_thickness < distance:
            p_thickness *=2
            count += 1
        return count
    else:
        return None

def fold_to(B):
    if B < 0: return None
    B *= 10_000
    L = 1
    M = 0
    while L < B:
        L *= 2
        M += 1
    return M
        


def fold_to(distance):
    if distance<0: return None
    d= distance//0.0001
    i=0
    while d>0:
       d//=2
       i+=1
    return i

def fold_to(distance):
    paper = 0.0001
    folds = 0
    if distance < 0:
        return None
    distance -= paper
    while distance > 0:
        distance -= paper
        paper *= 2
        folds += 1
    return folds


def fold_to(d,t = 0.0001):
    if 0 <= d <= t: 
        return 0
    elif d <= 0: 
        return None
        
    c = 0
    while t < d:
        c+=1
        t*=2
    return c

def fold_to(distance):
    n, count = 0.0001, 0
    while n < distance:
        n, count = n*2, count+1
    return None if distance < 0 else count

def fold_to(d):
    folds = 0
    t = 0.0001;
    if d < 0: return(None)
    while t <= d:
        t = t*2
        folds += 1
    return (folds)
    
    
    


def fold_to(distance):
    if distance < 0:
        return None
    count = 0
    paper = 0.0001
    while paper < distance:
        count += 1
        paper *= 2
    return count

def fold_to(distance):
    #your code here
    i = 0.0001
    n = 0
    if distance < 0 : return None
    while i<distance :
        i = i*2
        n += 1
    return n


def fold_to(distance):
    if distance >= 0:
        times = 0
        size = 0.0001
        while size < distance:
            size *= 2
            times += 1
        return times
    else:
        return None

def fold_to(distance):
    folds = 0
    h = 0.0001
    while h < distance:
        h *= 2
        folds += 1
    return folds if distance >= 0 else None

def fold_to(distance):
    thick=0.0001
    i=0
    if distance<0:
        return None
    else:
        while thick<distance:
            thick=2*thick;
            i=i+1;
    return i
    #your code here


from math import log2, ceil

def fold_to(d):
    return ceil(log2(d/0.0001)) if d>0.0001 else None if d<0 else 0

def fold_to(distance):
    if distance < 0: 
        return None
        
    res = 0
    d = 0.0001
    while d < distance: 
        d *= 2
        res +=1
    return res

def fold_to(distance):
    if distance < 0:
        return None
    res = 0
    l = 0.0001
    while l < distance:
        l *= 2
        res += 1 
        
    return res