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
11 changed files
with
439 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
Retos/Reto #0 - EL FAMOSO FIZZ BUZZ [Fácil]/c#/ernestoalbarez.cs
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,43 @@ | ||
using System; | ||
|
||
/* | ||
Reto #0: EL FAMOSO "FIZZ BUZZ" | ||
* Escribe un programa que muestre por consola (con un print) los | ||
* números de 1 a 100 (ambos incluidos y con un salto de línea entre | ||
* cada impresión), sustituyendo los siguientes: | ||
* - Múltiplos de 3 por la palabra "fizz". | ||
* - Múltiplos de 5 por la palabra "buzz". | ||
* - Múltiplos de 3 y de 5 a la vez por la palabra "fizzbuzz". | ||
*/ | ||
|
||
|
||
class Program | ||
{ | ||
static void Main() | ||
{ | ||
string fizz = "Fizz"; | ||
string buzz = "Buzz"; | ||
string fizzBuzz = "FizzBuzz"; | ||
|
||
for (int i=1; i<=100; i++) | ||
{ | ||
bool divisibleBy3 = i%3==0; | ||
bool divisibleBy5 = i%5==0; | ||
|
||
if (divisibleBy3 && divisibleBy5) { | ||
Console.WriteLine(fizzBuzz); | ||
} | ||
else if (divisibleBy3) { | ||
Console.WriteLine(fizz); | ||
} | ||
else if (divisibleBy5) { | ||
Console.WriteLine(buzz); | ||
} | ||
else { | ||
Console.WriteLine(i); | ||
} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
Retos/Reto #0 - EL FAMOSO FIZZ BUZZ [Fácil]/c++/ernestoalbarez.cpp
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,41 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
/* | ||
Reto #0: EL FAMOSO "FIZZ BUZZ" | ||
* Escribe un programa que muestre por consola (con un print) los | ||
* números de 1 a 100 (ambos incluidos y con un salto de línea entre | ||
* cada impresión), sustituyendo los siguientes: | ||
* - Múltiplos de 3 por la palabra "fizz". | ||
* - Múltiplos de 5 por la palabra "buzz". | ||
* - Múltiplos de 3 y de 5 a la vez por la palabra "fizzbuzz". | ||
*/ | ||
|
||
int main() | ||
{ | ||
std::string fizz = "Fizz"; | ||
std::string buzz = "Buzz"; | ||
std::string fizzBuzz = "FizzBuzz"; | ||
|
||
for (int i = 1; i <= 100; i++) { | ||
bool divisibleBy3 = i % 3 == 0; | ||
bool divisibleBy5 = i % 5 == 0; | ||
|
||
if (divisibleBy3 && divisibleBy5) { | ||
std::cout << fizzBuzz << std::endl; | ||
} | ||
else if (divisibleBy3) { | ||
std::cout << fizz << std::endl; | ||
} | ||
else if (divisibleBy5) { | ||
std::cout << buzz << std::endl; | ||
} | ||
else { | ||
std::cout << i << std::endl; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
35 changes: 35 additions & 0 deletions
35
Retos/Reto #0 - EL FAMOSO FIZZ BUZZ [Fácil]/c/ernestoalbarez.c
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,35 @@ | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
|
||
/* | ||
Reto #0: EL FAMOSO "FIZZ BUZZ" | ||
* Escribe un programa que muestre por consola (con un print) los | ||
* números de 1 a 100 (ambos incluidos y con un salto de línea entre | ||
* cada impresión), sustituyendo los siguientes: | ||
* - Múltiplos de 3 por la palabra "fizz". | ||
* - Múltiplos de 5 por la palabra "buzz". | ||
* - Múltiplos de 3 y de 5 a la vez por la palabra "fizzbuzz". | ||
*/ | ||
|
||
void main() { | ||
const char* fizz = "Fizz"; | ||
const char* buzz = "Buzz"; | ||
const char* fizzBuzz = "FizzBuzz"; | ||
|
||
for (int i=1; i<=100; i++) { | ||
bool divisibleBy3 = i%3==0; | ||
bool divisibleBy5 = i%5==0; | ||
|
||
if (divisibleBy3 && divisibleBy5) { | ||
puts(fizzBuzz); | ||
} else if (divisibleBy3) { | ||
puts(fizz); | ||
} else if (divisibleBy5) { | ||
puts(buzz); | ||
} else { | ||
printf("%d\n", i); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Retos/Reto #0 - EL FAMOSO FIZZ BUZZ [Fácil]/java/ernestoalbarez.java
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,32 @@ | ||
/* | ||
Reto #0: EL FAMOSO "FIZZ BUZZ" | ||
* Escribe un programa que muestre por consola (con un print) los | ||
* números de 1 a 100 (ambos incluidos y con un salto de línea entre | ||
* cada impresión), sustituyendo los siguientes: | ||
* - Múltiplos de 3 por la palabra "fizz". | ||
* - Múltiplos de 5 por la palabra "buzz". | ||
* - Múltiplos de 3 y de 5 a la vez por la palabra "fizzbuzz". | ||
*/ | ||
|
||
public class ernestoalbarez { | ||
public static void main(String[] args) { | ||
for (int i=1; i<=100; i++) { | ||
StringBuilder output = new StringBuilder(); | ||
|
||
if (i % 3 == 0) { | ||
output.append("Fizz"); | ||
} | ||
if (i % 5 == 0) { | ||
output.append("Buzz"); | ||
} | ||
|
||
System.out.println( | ||
output.length()>0 ? | ||
output.toString() : | ||
String.valueOf(i) | ||
); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Retos/Reto #0 - EL FAMOSO FIZZ BUZZ [Fácil]/javascript/ernestoalbarez.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,24 @@ | ||
/* | ||
Reto #0: EL FAMOSO "FIZZ BUZZ" | ||
* Escribe un programa que muestre por consola (con un print) los | ||
* números de 1 a 100 (ambos incluidos y con un salto de línea entre | ||
* cada impresión), sustituyendo los siguientes: | ||
* - Múltiplos de 3 por la palabra "fizz". | ||
* - Múltiplos de 5 por la palabra "buzz". | ||
* - Múltiplos de 3 y de 5 a la vez por la palabra "fizzbuzz". | ||
*/ | ||
|
||
for (let i=1; i<=100; i++) { | ||
let output = ""; | ||
|
||
if (i%3 === 0) { | ||
output += "Fizz"; | ||
} | ||
if (i%5 === 0) { | ||
output += "Buzz"; | ||
} | ||
console.log(output || `${i}`); | ||
} | ||
|
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,21 @@ | ||
''' | ||
Crea una función que sea capaz de detectar si existe un viernes 13 en el mes y el año indicados. | ||
- La función recibirá el mes y el año y retornará verdadero o falso. | ||
''' | ||
import datetime | ||
|
||
def friday_13(month, year) ->bool : | ||
try: | ||
return datetime.date(year, month, 13).isoweekday() == 5 | ||
except: | ||
return False | ||
|
||
def main(): | ||
|
||
print(friday_13(6,2023)) | ||
print(friday_13(4,2023)) | ||
print(friday_13(10,2023)) | ||
print(friday_13(1,2023)) | ||
|
||
if __name__ == '__main__': | ||
main() |
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,24 @@ | ||
from datetime import datetime | ||
import unittest | ||
|
||
def FridayThe13th(month, year): | ||
date = datetime(year, month, 13) | ||
|
||
return True if date.weekday() == 4 else False | ||
|
||
class test_viernes_13(unittest.TestCase): | ||
def test_1(self): | ||
self.assertTrue(FridayThe13th(1,2023)) | ||
def test_2(self): | ||
self.assertEqual(FridayThe13th(1,2025),False) | ||
def test_3(self): | ||
with self.assertRaises(TypeError): | ||
FridayThe13th("01","2026") | ||
def test_4(self): | ||
self.assertEqual(FridayThe13th("1","2023"),True) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
|
||
|
56 changes: 56 additions & 0 deletions
56
Retos/Reto #26 - TESTING [Media]/python/ingjavierpinilla.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,56 @@ | ||
import unittest | ||
from datetime import datetime | ||
|
||
|
||
def has_friday_13(year: int, month: int) -> bool: | ||
"""Esta funcion retorna verdadero si para un año y mes dado existe un viernes 13 | ||
Args: | ||
year (int): | ||
month (int): | ||
Returns: | ||
bool: | ||
""" | ||
if not isinstance(year, int): | ||
raise TypeError("Year invalid, enter a valid integer number") | ||
if not isinstance(month, int): | ||
raise TypeError("Month invalid, enter a valid integer number") | ||
|
||
return datetime(year, month, 13).weekday() == 4 | ||
|
||
|
||
class TestIsFriday13(unittest.TestCase): | ||
def setUp(self): | ||
self.is_friday_13 = {"year": 2023, "month": 10} | ||
self.not_friday_13 = {"year": 2023, "month": 7} | ||
|
||
def test_invalid_year(self): | ||
with self.assertRaises(TypeError): | ||
has_friday_13(year="1520", month=7) | ||
|
||
def test_invalid_month(self): | ||
with self.assertRaises(TypeError): | ||
has_friday_13(year=1520, month=(1520, 1)) | ||
|
||
def test_expected_return(self): | ||
self.assertIsInstance(has_friday_13(year=1520, month=7), bool) | ||
|
||
def test_valid_friday_13(self): | ||
self.assertIs( | ||
has_friday_13( | ||
year=self.is_friday_13["year"], month=self.is_friday_13["month"] | ||
), | ||
True, | ||
) | ||
|
||
def test_invalid_friday_13(self): | ||
self.assertIsNot( | ||
has_friday_13( | ||
year=self.not_friday_13["year"], month=self.not_friday_13["month"] | ||
), | ||
True, | ||
) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,27 @@ | ||
import unittest | ||
from datetime import date | ||
|
||
def friday_13(month, year) -> bool : | ||
try: | ||
return date(year, month, 13).isoweekday() == 5 | ||
except: | ||
return False | ||
|
||
class FridayTestCase(unittest.TestCase): | ||
|
||
def test_is_friday_13(self): | ||
day = friday_13(1,2023) | ||
self.assertTrue(day) | ||
|
||
def test_is_not_friday_13(self): | ||
day = friday_13(2,2023) | ||
self.assertFalse(day) | ||
|
||
def test_invalid_date(self): | ||
day = friday_13(13,2023) | ||
self.assertFalse(day) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,40 @@ | ||
import Foundation | ||
import XCTest | ||
|
||
// Se aconseja usar el script en Playground para poder usar XCTest | ||
|
||
func isFriday13th(month: Int, year: Int) -> Bool { | ||
|
||
let calendar = Calendar.current | ||
var components = DateComponents() | ||
|
||
components.year = year | ||
components.month = month | ||
components.day = 13 | ||
|
||
if let date = calendar.date(from: components) { | ||
let weekday = calendar.component(.weekday, from: date) | ||
return weekday == 6 | ||
} | ||
|
||
return false | ||
} | ||
|
||
class IsFriday13thTests: XCTestCase { | ||
|
||
func testIsFriday13th() { | ||
|
||
XCTAssertTrue(isFriday13th(month: 8, year: 2021)) | ||
XCTAssertTrue(isFriday13th(month: 1, year: 2023)) | ||
|
||
|
||
XCTAssertFalse(isFriday13th(month: 5, year: 2023)) | ||
XCTAssertFalse(isFriday13th(month: 7, year: 2025)) | ||
} | ||
} | ||
|
||
IsFriday13thTests.defaultTestSuite.run() | ||
|
||
|
||
|
||
|
Oops, something went wrong.