# IAL-501 (Prof. Dr. Silvio do Lago Pereira)

from util import *

#-----------------------------------------------------------
# Exemplo 1
#-----------------------------------------------------------

def média(v): 
    n = len(v)      
    s = 0
    for i in range(n):
        s += v[i]
    m = s/n
    return m

#-----------------------------------------------------------
# Exemplo 2
#-----------------------------------------------------------

def crescente(v):       
    n = len(v)
    for i in range(n-1):
        if v[i]>v[i+1]:
            return False
    return True

#-----------------------------------------------------------
# Exemplo 4
#-----------------------------------------------------------

def f0(n):
    c = 0
    p =1
    for i in range(n):
        p += 1
        c += 1
        p += 1
    p += 1
    return c, p+1

#-----------------------------------------------------------
# Exercicio 3
#-----------------------------------------------------------

def f2(n):
    c = 0                  
    for i in range(n):
        for j in range(10):
            c += 1
    return c

#-----------------------------------------------------------
# Exercicio 4
#-----------------------------------------------------------

def f3(n):
    c = 0
    while n>1:
        c += 1
        n //= 2
    return c

#-----------------------------------------------------------
# Exercicio 5
#-----------------------------------------------------------

def f4(n):
    c = 0
    for i in range(n):
        m = n 
        while m>1:
            c += 1
            m //= 2
    return c

#-----------------------------------------------------------
# Exercicio 6
#-----------------------------------------------------------

def f5(n):
    c = 0
    for i in range(n):
        for j in range(i+1,n):
            c += 1
    return c

#-----------------------------------------------------------
# Exercicio 8
#-----------------------------------------------------------

def f6(n):
    c = 0                  
    for i in range(n*n+1):
        for j in range(1,i+1):
            c += 1
    return c

#-----------------------------------------------------------
# Exercicio 10
#-----------------------------------------------------------

def f7(n):
    c = 0
    for i in range(n):
        for j in range(2*i): 
            for k in range(j): c += 1
    return c

#-----------------------------------------------------------
# Exercicio 12
#-----------------------------------------------------------

def f8(n):
    c = 0
    for i in range(floor(log(n,2))):
        for j in range(2): 
            for k in range(n): c += 1
    return c

#-----------------------------------------------------------
# Exercicio 14
#-----------------------------------------------------------

def f9(n):
    c = 0                  
    for i in range(n):
        for j in range(2**i):
            c += 1
    return c

#-----------------------------------------------------------
# Exemplo 8
#-----------------------------------------------------------

def p1(x,n): 
    if n==0: return 1
    return x * p1(x,n-1)

#-----------------------------------------------------------
# Exemplo 9
#-----------------------------------------------------------

def T1(n):
    if n==0: return 0
    return 1 + T1(n-1)

def S1(n): return n

#-----------------------------------------------------------
# Exemplo 10
#-----------------------------------------------------------

def p2(x,n): 
    if n==0: return 1
    if n==1: return x
    return p2(x*x, n//2) if n%2==0 else x*p2(x*x, n//2)

#-----------------------------------------------------------
# Exemplo 11
#-----------------------------------------------------------

def T2(n):
    if n<2: return 0
    return 2 + T2(floor(n/2))

def S2(n): return 2*lg(n)

#-----------------------------------------------------------
# Exercicio 16
#-----------------------------------------------------------

def r1(n):
    if n==0: return 0
    c = 0                  
    for i in range(2): c += 1
    return c + r1(n-1)

#-----------------------------------------------------------
# Exercicio 17
#-----------------------------------------------------------

def E1(n): return 2*n # estimada

#-----------------------------------------------------------
# Exercicio 18
#-----------------------------------------------------------

def r2(n):
    if n==0: return 0
    return r1(n) + r2(n-1)

#-----------------------------------------------------------
# Exercicio 19
#-----------------------------------------------------------

def E2(n): return n**2 + n

#-----------------------------------------------------------
# Exercicio 20
#-----------------------------------------------------------

def h(n,o,a,d):
    if n >= 1:
        h(n-1,o,d,a)
        print('move(%s,%s)' % (o,d))
        h(n-1,a,o,d)
