-
Notifications
You must be signed in to change notification settings - Fork 0
/
punto4_examen1.py
49 lines (38 loc) · 1.06 KB
/
punto4_examen1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 23 16:28:29 2023
@author: Nicolás Rincón Sánchez
"""
# Taken from the exam explicitly
def funRecursiva(n):
"""
funRecursiva: Funcion recursiva de parcial 1
Creada por Rubén Francisco Manrique Piramanrique
n: nat
"""
assert (isinstance(n,int)), "Solo se aceptan numeros enteros"
assert (n>=0), "Solo se aceptan numeros enteros positivos"
if n==0:
return 0
elif n==1:
return 2
elif n==2:
return 68
return 128*funRecursiva(n-3)-32*funRecursiva(n-2)-14*funRecursiva(n-1)
# Function created to evaluate with the solution to the recurrence
def solucionRecursiva(n:int)->int:
"""
Parameters
----------
n : int
A number given in order to evaluate the n-th element of a recursion.
Returns
-------
int
The n-th element in a sequence defined by a recurrence relation.
"""
c1 = 1
c2 = -1
c3 = 1
eq = c1*2**n + c2*(-8)**n + c3*n*(-8)**n
return eq