-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5839 from Pancratzia/main
Reto #21 - javascript
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
Retos/Reto #20 - LA TRIFUERZA [Media]/javascript/Pancratzia.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* ¡El nuevo "The Legend of Zelda: Tears of the Kingdom" ya está disponible! | ||
* | ||
* Crea un programa que dibuje una Trifuerza de "Zelda" | ||
* formada por asteriscos. | ||
* - Debes indicarle el número de filas de los triángulos con un entero positivo (n). | ||
* - Cada triángulo calculará su fila mayor utilizando la fórmula 2n-1. | ||
* | ||
* Ejemplo: Trifuerza 2 | ||
* | ||
* * | ||
* *** | ||
* * * | ||
* *** *** | ||
* | ||
*/ | ||
|
||
function dibujarTriFuerza(n = 1) { | ||
|
||
baseTriangulo = 2*n - 1; | ||
let trifuerza = ""; | ||
|
||
for (let i = 0; i < n; i++) { | ||
trifuerza += " ".repeat(baseTriangulo - i) + "*".repeat(2 * i + 1) + "\n"; | ||
} | ||
|
||
|
||
let espaciosDer = n-1; | ||
let espaciosIzq = 2*n - 1; | ||
|
||
//Dibujo los dos triangulos inferiores | ||
for (let i = 0; i < n; i++) { | ||
|
||
trifuerza += " ".repeat(espaciosDer) + "*".repeat(2 * i + 1) + " ".repeat(espaciosIzq) + "*".repeat(2 * i + 1) + "\n"; | ||
|
||
espaciosDer--; | ||
espaciosIzq-=2; | ||
} | ||
|
||
console.log(trifuerza); | ||
} | ||
|
||
dibujarTriFuerza(2); | ||
dibujarTriFuerza(3); | ||
dibujarTriFuerza(10); | ||
|
34 changes: 34 additions & 0 deletions
34
Retos/Reto #21 - NÚMEROS PRIMOS GEMELOS [Media]/javascript/Pancratzia.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Crea un programa que encuentre y muestre todos los pares de números primos | ||
* gemelos en un rango concreto. | ||
* El programa recibirá el rango máximo como número entero positivo. | ||
* | ||
* - Un par de números primos se considera gemelo si la diferencia entre | ||
* ellos es exactamente 2. Por ejemplo (3, 5), (11, 13) | ||
* | ||
* - Ejemplo: Rango 14 | ||
* (3, 5), (5, 7), (11, 13) | ||
*/ | ||
function esPrimo(numero){ | ||
if (numero == 0 || numero == 1 || numero == 4) return false; | ||
for (let x = 2; x < numero / 2; x++) { | ||
if (numero % x == 0) return false; | ||
} | ||
return true; | ||
} | ||
|
||
function primosGemelos(rango = 10){ | ||
let primosGemelos=""; | ||
|
||
for(let i=1; i<=rango; i++){ | ||
if(esPrimo(i) && esPrimo(i+2)){ | ||
primosGemelos += "("+i+", "+(i+2)+") "; | ||
} | ||
} | ||
|
||
console.log(primosGemelos); | ||
|
||
} | ||
|
||
primosGemelos(10); | ||
primosGemelos(30); |