# -*- coding: utf-8 -*-
"""Tarea5.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1s668ECNhGDFUbyjSOWZ1QPmFKZCsBFf6
"""

# 1, T(n) = 4
from time import time
def ejemplo1( n ):
  start_time = time()
  c = n + 1
  d = c * n
  e = n * n
  total = c + e - d
  print(f"total = { total }")
  elapsed_time = time() - start_time
  print("Tiempo transcurrido: %0.10f segundos." % elapsed_time)

for entrada in range(100, 1100, 100):
  print(entrada)
  ejemplo1(entrada)
  print(" ")

# 2, T(n) = 1 + n^2
from time import time
def ejemplo2( n ):
  start_time = time()
  contador = 0
  for i in range( n ) :
    for j in range( n ) :
      contador += 1
  elapsed_time = time() - start_time
  print("Tiempo transcurrido: %0.10f segundos." % elapsed_time)
  return contador

for entrada in range(100, 1100, 100):
  print(entrada)
  ejemplo2(entrada)
  print(" ")

# 3, T(n) = 102
from time import time
def ejemplo3( n ): # n=4
  start_time = time()
  x = n * 2 # x = 8
  y = 0   # y = 0
  for m in range( 100 ): #3
    y = x - n   # y = 4
  elapsed_time = time() - start_time
  print("Tiempo transcurrido: %0.10f segundos." % elapsed_time)
  return y

for entrada in range(100, 1100, 100):
  print(entrada)
  ejemplo3(entrada)
  print(" ")

# 4, T(n) = 3
from time import time
def ejemplo4( n ):
  start_time = time()
  x = 3 * 3.1416 + n
  y = x + 3 * 3 - n
  z = x + y
  elapsed_time = time() - start_time
  print("Tiempo transcurrido: %0.10f segundos." % elapsed_time)
  return z

for entrada in range(100, 1100, 100):
  print(entrada)
  ejemplo4(entrada)
  print(" ")

# 5, T(x) = 1 + x
from time import time
def ejemplo5( x ):
  start_time = time()
  n = 10
  for j in range( 0 , x , 1 ):
    n = j + n
  elapsed_time = time() - start_time
  print("Tiempo transcurrido: %0.10f segundos." % elapsed_time)
  return n

for entrada in range(100, 1100, 100):
  print(entrada)
  ejemplo5(entrada)
  print(" ")

# 6 con modificación
from time import time
def ejemplo6( n ):
  start_time = time()
  data=[[[1 for x in range(n)] for x in range(n)] 
        for x in range(n)]
  suma = 0
  for d in range(n):
      for r in range(n):
          for c in range(n):
              suma += data[d][r][c]
  elapsed_time = time() - start_time
  print("Tiempo transcurrido: %0.10f segundos." % elapsed_time)
  return suma

for entrada in range(100, 1100, 100):
  print(entrada)
  ejemplo6( entrada )
  print(" ")