EASY PYTHON FUNCTIONS
COMPROBAR SI ES CAPICUA
def capicua(num: str) -> str:
m = int(len(num)/2)
return 'es capicua' if num[:m] == num[:-m] else 'no es capicua'
COMPROBAR SI ES PRIMO
def esprimo(num: int) -> str:
listaNumeros = [i for i in range(num)]
for i in listaNumeros:
if i+1 == num:
return 'es primo'
elif num%(i+1) == 0 and (i+1) != 1:
return 'no es primo'
else:
continue
SIGUIENTE PRIMO
def siguientePrimo(num: int) -> str:
listaNumeros = [i for i in range((num+1), (num*1000))]
for i in listaNumeros:
if esprimo(i) == 'es primo':
return f'el siguiente primo {i}'
else:
continue
CALCULAR POTENCIA
def potencia(base: int, exponente: int) -> int:
num = 1
for _ in range(exponente):
num *= base
return num
CALCULAR NUMERO DE DIGITOS
def digitos(num: int) -> str:
n = 0
for i in str(num):
n += 1
return f'tiene {n} digitos'
VOLTEAR NUMERO
def voltea(num: int) -> str:
n = ''
num = str(num)
for i in range(1, len(num) + 1):
n += num[-i]
return n
BINARY TREE JAVA EXERCISE
Diseñe un algoritmo que dado un árbol n-ario Tree<E> y un predicado sobre E devuelva una lista List<Boolean> de forma que el elemento i-ésimo de la lista será “True” si todos los elementos del nivel i cumplen el predicado.
public static List solucion_recursiva (Tree t, Predicate p){
List res = new ArrayList<>();
recursivo (t,p,0,res);
return res;
}
private static void recursivo(Tree tree, Predicate pred, int nivel, List res) {
if(res.size() <= nivel) res.add(true);
switch (tree) {
case TEmpty() -> {;}
case TLeaf(var lb) -> {
Boolean r = pred.test(lb) && res.get(nivel);
res.set(nivel, r);
}
case TNary(var lb, var chd) -> {
Boolean r = pred.test(lb) && res.get(nivel);
res.set(nivel, r);
chd.forEach(tc -> recursivo(tc, pred, nivel + 1, res));
}
}
SING UP (IISSI II)
SIGN IN
<div class="log-in">
<h2>SIGN IN</h2>
<hr>
<form action="get">
<fieldset>
<legend>USER INFORMATION</legend>
<div class="input">
<label for="name">Name</label>
<input type="text" placeholder="Name" autofocus required id="name" name="name" title="name">
</div>
<div class="input">
<label for="last-name">Last Name</label>
<input type="text" placeholder="Last Name" id="last-name" name="last-name" title="last-name">
</div>
<div class="input">
<label for="birthDate">Birth date</label>
<input type="date" name="birthDate" id="birthDate" style="color: #868686;">
</div>
<div class="input">
<label for="dni">DNI</label>
<input type="text" name="dni" id="dni" title="dni" placeholder="DNI" pattern="^[0-9]{8}[A-Za-z]$">
</div>
<div class="input">
<label for="phone">Phone Number</label>
<input type="text" placeholder="Phone Number" name="phone" id="phone" title="phone">
</div>
<div class="input">
<label for="email">Email</label>
<input type="text" placeholder="Email" required id="email" name="email" title="email">
</div>
<div class="input">
<label for="user-name">User Name</label>
<input type="text" placeholder="User Name" required id="user-name" name="user-name" title="user-name">
</div>
<div class="input">
<label for="password">Password</label>
<input type="password" name="password" id="password" title="password" placeholder="Password">
</div>
<button type="submit">LOG IN</button>
</fieldset>
</form>
</div>
.log-in {
justify-content: center;
background-color: #1c1c1c;
color: #fff;
border-radius: 6px;
padding: 10px 20px;
max-width: 400px;
}
.log-in h2 {
margin-bottom: 5px;
}
.log-in fieldset {
border-radius: 6px;
border-color: #1a8100;
padding: 0 10px 10px 10px;
}
.log-in legend {
padding: 0 5px;
font-weight: 700;
}
.log-in label {
padding-right: 5px;
}
.log-in input {
padding: 2px;
background: none;
border: 0px;
border-bottom: 1px solid #fff;
color: #fff;
font-family: 'Quicksand', sans-serif;
outline: none;
}
.log-in .input {
display: flex;
justify-content: space-between;
gap: 30px;
}
.log-in input::placeholder {
color: #868686;
}
.log-in button {
padding: 3px;
margin-top: 10px;
}
.log-in button {
background-image: linear-gradient(-45deg, #73c260, #1a8100, #125a00);
border-radius: 4px;
border-style: none;
color: #fff;
font-family: 'Quicksand',sans-serif;
font-size: 14px;
padding: 5px 8px;
text-align: center;
}
.log-in button:hover {
box-shadow: #1a8100 0 1px 7px;
transition-duration: .05s;
}