forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mouredev:main' into main
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
Retos/Reto #0 - EL FAMOSO FIZZ BUZZ [Fácil]/go/raynerpv2022.go
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,20 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("FIZZ BUZZ") | ||
// if condition | ||
for i := 1; i < 101; i++ { | ||
if i%3 == 0 && i%5 == 0 { | ||
fmt.Println("FIZZ BUZZ") | ||
} else if i%3 == 0 { | ||
fmt.Println("FIZZ") | ||
} else if i%5 == 0 { | ||
fmt.Println("BUZZ") | ||
} else { | ||
fmt.Println(i) | ||
} | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
Retos/Reto #0 - EL FAMOSO FIZZ BUZZ [Fácil]/swift/allbertoMD.swift
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,28 @@ | ||
import Foundation | ||
|
||
func fizzBuzz(num: Int = 100) { | ||
for n in 0...num { | ||
if n % 3 == 0 && n % 5 == 0 { | ||
print("fizzbuzz") | ||
continue | ||
} | ||
|
||
if n % 3 == 0 { | ||
print("fizz") | ||
continue | ||
} | ||
|
||
if n % 5 == 0 { | ||
print("buzz") | ||
continue | ||
} | ||
|
||
print(n) | ||
} | ||
} | ||
|
||
fizzBuzz() | ||
|
||
|
||
|
||
|
54 changes: 54 additions & 0 deletions
54
Retos/Reto #4 - PRIMO, FIBONACCI Y PAR [Media]/python/Hugodiazz.py
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,54 @@ | ||
# Escribe un programa que, dado un número, compruebe y muestre si es primo, fibonacci y par. | ||
# Ejemplos: | ||
# - Con el número 2, nos dirá: "2 es primo, fibonacci y es par" | ||
# - Con el número 7, nos dirá: "7 es primo, no es fibonacci y es impar" | ||
|
||
|
||
|
||
def esPar(numero): | ||
if numero % 2 == 0: | ||
return 'es par' | ||
else: | ||
return 'es impar' | ||
|
||
def esPrimo(numero): | ||
if numero <= 1: | ||
return 'no es primo' | ||
elif numero <= 3: | ||
return 'es primo' | ||
elif numero % 2 == 0 or numero % 3 == 0: | ||
return 'no es primo' | ||
i = 5 | ||
while i * i <= numero: | ||
if numero % i == 0 or numero % (i + 2) == 0: | ||
return 'no es primo' | ||
i += 6 | ||
return 'es primo' | ||
|
||
def enFibo(numero): | ||
a, b, i = 0, 1, 0 | ||
while i <= numero: | ||
c = a + b | ||
a = b | ||
b = c | ||
|
||
if a == numero: | ||
return 'es fibonacci' | ||
break | ||
elif a > numero: | ||
return 'no es fiboncacci' | ||
break | ||
|
||
i += 1 | ||
return '' | ||
|
||
def evaluarNumero(numero): | ||
par = esPar(numero) | ||
fibo = enFibo(numero) | ||
primo = esPrimo(numero) | ||
|
||
print(str(numero), primo, fibo + ' y ', par) | ||
|
||
|
||
print(evaluarNumero(2)) | ||
print(evaluarNumero(7)) |
19 changes: 19 additions & 0 deletions
19
Retos/Reto #8 - EL GENERADOR PSEUDOALEATORIO [Media]/python/restevean.py
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,19 @@ | ||
import time | ||
|
||
|
||
# Classical method known as the linear congruential generator (LCLG) | ||
def pseudo_random_generator(seed=42): | ||
if seed is None: | ||
seed = int(time.time() * 1000) % 2 ** 32 | ||
a = 1664525 | ||
c = 1013904223 | ||
m = 2**32 | ||
xn = seed | ||
while True: | ||
xn = (a * xn + c) % m | ||
yield xn % 101 # Devuelve un número entre 0 y 100 | ||
|
||
|
||
gen = pseudo_random_generator() | ||
for _ in range(10): | ||
print(next(gen)) |