From 9dcecc33d12258fdbc741a864b103224169b28fe Mon Sep 17 00:00:00 2001 From: Juan Date: Wed, 17 Jan 2024 15:19:02 -0600 Subject: [PATCH 1/2] Reto #8 - swift --- .../swift/juanjoseen.swift | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Retos/Reto #8 - EL GENERADOR PSEUDOALEATORIO [Media]/swift/juanjoseen.swift diff --git a/Retos/Reto #8 - EL GENERADOR PSEUDOALEATORIO [Media]/swift/juanjoseen.swift b/Retos/Reto #8 - EL GENERADOR PSEUDOALEATORIO [Media]/swift/juanjoseen.swift new file mode 100644 index 0000000000..f0a522b846 --- /dev/null +++ b/Retos/Reto #8 - EL GENERADOR PSEUDOALEATORIO [Media]/swift/juanjoseen.swift @@ -0,0 +1,27 @@ +import UIKit + +class RandomGenerator { + private let primes: [Int] = [2, 3, 5, 7, 11, 13, 17, 19, 23, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167] + private var index: Int = 0 + + private init() {} + + static let shared: RandomGenerator = RandomGenerator() + + func random() -> Int { + let time: Int = Int(Date().timeIntervalSince1970 * 1000) + let part1: Int = Int(time / getPrime()) + let part2: Int = Int(part1 * getPrime()) + return part2 % 101 + } + + private func getPrime() -> Int { + let prime: Int = primes[index] + index = (index + 1) % primes.count + return prime + } + +} + +let rg: RandomGenerator = RandomGenerator.shared +print(rg.random()) From aee475e29cc1dc5e99a7f0235ffde5e6d15103a6 Mon Sep 17 00:00:00 2001 From: restevean Date: Thu, 18 Jan 2024 07:17:50 +0100 Subject: [PATCH 2/2] Retos #0 y #1 --- .../python/restevean.py" | 38 +++++++++++++++++ .../python/restevean.py" | 42 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 "Retos/Reto #0 - EL FAMOSO FIZZ BUZZ [F\303\241cil]/python/restevean.py" create mode 100644 "Retos/Reto #1 - EL LENGUAJE HACKER [F\303\241cil]/python/restevean.py" diff --git "a/Retos/Reto #0 - EL FAMOSO FIZZ BUZZ [F\303\241cil]/python/restevean.py" "b/Retos/Reto #0 - EL FAMOSO FIZZ BUZZ [F\303\241cil]/python/restevean.py" new file mode 100644 index 0000000000..d110ee2ab8 --- /dev/null +++ "b/Retos/Reto #0 - EL FAMOSO FIZZ BUZZ [F\303\241cil]/python/restevean.py" @@ -0,0 +1,38 @@ +""" + Write a function that a list of numbers from 1 to 100, replacing: + - Multiples of 3 by the word "fizz". + - Multiples of 5 by the word "buzz". + - Multiples of 3 and 5 by the word "fizzbuzz". +""" + + +def fizzbuzz_1(): + numbers = [] + for num in range(1, 101): + if num % 3 == 0 and num % 5 == 0: + numbers.append("fizzbuzz") + elif num % 3 == 0: + numbers.append("fizz") + elif num % 5 == 0: + numbers.append("buzz") + else: + numbers.append(num) + + return numbers + + +def fizzbuzz_2(): + for i in range(1, 101): + if i % 3 == 0 and i % 5 == 0: + print("fizzbuzz") + elif i % 3 == 0: + print("fizz") + elif i % 5 == 0: + print("buzz") + else: + print(i) + + +if __name__ == "__main__": + print(fizzbuzz_1()) + fizzbuzz_2() diff --git "a/Retos/Reto #1 - EL LENGUAJE HACKER [F\303\241cil]/python/restevean.py" "b/Retos/Reto #1 - EL LENGUAJE HACKER [F\303\241cil]/python/restevean.py" new file mode 100644 index 0000000000..bf9873e331 --- /dev/null +++ "b/Retos/Reto #1 - EL LENGUAJE HACKER [F\303\241cil]/python/restevean.py" @@ -0,0 +1,42 @@ +""" +Write a program that receives a text and transforms natural language to + "hacker language" (known really as "leet" or "1337"). This language + is characterized by replacing alphanumeric characters. +- Use this table (https://www.gamehouse.com/blog/leet-speak-cheat-sheet/) + with the alphabet and numbers in "leet". + (Use the first option of each transformation. For example "4" for the "a") +""" + + +LEET_DICT = {'A': '4', 'B': 'I3', + 'C': '[', 'D': ')', 'E': '3', + 'F': '|=', 'G': '&', 'H': '#', + 'I': '1', 'J': ',_|', 'K': '>|', + 'L': '1', 'M': '/\/\/', 'N': '^/', + 'O': '0', 'P': '|*', 'Q': '(_,)', + 'R': 'I2', 'S': '5', 'T': '7', + 'U': '(_)', 'V': '\/', 'W': '\/\/', + 'X': '><', 'Y': 'j', 'Z': '2', + '1': 'L', '2': 'R', '3': 'E', + '4': 'A', '5': 'S', '6': 'b', + '7': 'T', '8': 'B', '9': 'G', + '0': 'o' + } + + +def leet(message): + result = "" + + for character in message: + if character == " ": + result += " " + else: + result += LEET_DICT[character.upper()] + " " + + return result[:-1] + + +if __name__ == "__main__": + # Test the program + text = "Hello World" + print(leet(text))