This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
code__wars.py
206 lines (154 loc) · 4.52 KB
/
code__wars.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Minima cantidad de Monedas
import numpy as np
from sympy.utilities.iterables import multiset_permutations
# HALLAR EL DETERMINANTE DE UNA MATRIZ DADA EN FORMA DE STRING
def matrizStringDet(strArr):
matriz = []
lista = []
for i in strArr:
if i != "<>":
lista.append(int(i))
else:
matriz.append(lista)
lista = []
matriz.append(lista)
n_array = np.array(matriz)
det = np.linalg.det(n_array)
return round(det)
# n = ["5","0","<>","0","5"]
# b = ["1","2","4","<>","2","1","1","<>","4","1","1"]
def aux(allmonedas, num):
final = num
monedas = 0
for moneda in allmonedas:
while final >= moneda:
final -= moneda
monedas += 1
return monedas
def Coins(num):
final = []
a = np.array([11,9,7,5,1])
for p in multiset_permutations(a):
final.append(aux(p, num))
return min(final)
# n = 6
# b = 16
# c = 25
# Sub lista Creciente
def subCreciente(arr):
sumalistas = []
aux = arr[::]
for i in range(len(arr)):
count = 0
lista_num = [arr[i]]
aux.remove(arr[i])
for j in range(len(aux)):
if lista_num[count] < aux[j]:
lista_num.append(aux[j])
count += 1
sumalistas.append(len(lista_num))
return max(sumalistas)
# lista = [10, 22, 9, 33, 21, 50, 41, 60, 22, 68, 90]
# lista_1 = [9, 9, 4, 2]
# DIVISION DE PALABRA ENTRE FRAGMENTOS DADOS
def DividorPalabra(strArr):
for i in range(len(strArr[0])):
if strArr[0][:i+1] in strArr[1] and strArr[0][i+1:] in strArr[1] and strArr[0][:i+1] + strArr[0][i+1:] == strArr[0]:
return f'{strArr[0][:i+1]},{strArr[0][i+1:]}'
return "not possible"
# lista_1 = ["abcgefd", "a,ab,abc,abcg,b,c,dog,e,efd,zzzz"]
# lista = ["baseball", "a,all,b,ball,bas,base,cat,code,d,e,quit,z"]
# Columnas Suma Mayor tamaño igual altura
def ArrayChallenge(arr):
lista = []
for i in range(len(arr)):
h = arr[i]
newarr = arr[::]
newarr.remove(arr[i])
for j in range(len(arr)-1):
if newarr[j] >= arr[i]:
h += arr[i]
else:
lista.append(h)
return max(lista)
# lista = [6, 3, 1, 4, 12, 4]
# lista_1 = [5, 6, 7, 4, 1]
# lista_2 = [2, 1, 3, 4, 1]
# Promedio igual a moda
def Prom_Moda(arr):
count = {}
for i in arr:
count[arr.count(i)] = i
promedio = int(sum(arr)/len(arr))
if promedio == count[max(count)]:
return 1
else:
return 0
# lista = [5, 3, 3, 3, 1]
# 2X2 de VOCALES EN UNA MATRIZ
vocales = ["a", "e","i", "o", "u"]
def vocales2X2(strArr):
for i in range(int(len(strArr)-1)):
for j in range(int(len(strArr[0])-1)):
if strArr[i][j] in vocales and strArr[i][j+1] in vocales and strArr[i+1][j] in vocales and strArr[i+1][j+1] in vocales:
return(f"{i}-{j}")
break
return "not found"
# matriz = ["abcd", "eikr", "oufj"]
# matriz_1 = ["aqrst", "ukaei", "ffooo"]
# matriz_2 = ["gg", "ff"]
# ***ENCUENTRA LOS DIVISORES EXACTOS***
def Divisor(objetivo):
lista = [i for i in range(2,objetivo) if objetivo % i == 0]
if not lista:
objetivo = str(objetivo)
return f'{objetivo} is prime'
else:
return lista
print(Divisor(int(input('Dime un número: '))))
"""# ***ELEVA CADA DIGITO DE UN NUMERO***"""
def square_digits(num):
num = str(num)
ans = ''
for i in num:
ans += str(int(int(i)**2))
return int(ans)
print(square_digits(int(input('Dime un número: '))))
"""# ***SUMAR DIGITOS***"""
def sum_digits(number):
return sum([int(x) for x in str(number)])
print(sum_digits(int(input('Dime un número: '))))
"""# ***PALABRA ALREVEZ***"""
def spin_words(sentence):
return sentence[::-1]
print(spin_words(input('Dime una palabra: ')))
"""# ***TRIBONACCI***
Hacer una secuercia donde sume los anteriores 3 numeros hasta llegar al n-abo elemento de la lista. **rango = n**
"""
def tribonacci(trio_inicial, rango):
#len(Lista final)
hasta = rango
#lista = [0,1,2]
lista = trio_inicial
contador =0
while contador < rango - 3:
operacion = lista[contador] + lista[contador+1] + lista[contador+2]
lista.append(operacion)
contador +=1
return lista
trio_inicial = [2,5,21]
n = 19
print(tribonacci(trio_inicial, n))
"""# ***PERMUTAR***"""
def inserta(x, lst, i):
return lst[:i] + [x] + lst[i:]
def inserta_multiple(x, lst):
return [inserta(x, lst, i) for i in range(len(lst) + 1)]
def permuta(c):
if len(c) == 0:
return [[]]
return sum([inserta_multiple(c[0], s)
for s in permuta(c[1:])],
[])
lista = [1,2,3]
print(permuta(lista))