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.
- Loading branch information
Showing
3 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
Retos/Reto #37 - COLORES HEX Y RGB [Media]/python/mouredev.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,37 @@ | ||
import re | ||
|
||
def hex_to_rgb(hex: str) -> tuple: | ||
|
||
hex = hex.lstrip("#") | ||
|
||
regex = re.compile(r"^[0-9a-fA-F]{6}$") | ||
if regex.match(hex): | ||
|
||
r = int(hex[0:2], 16) | ||
g = int(hex[2:4], 16) | ||
b = int(hex[4:6], 16) | ||
|
||
return (r, g, b) | ||
|
||
return (0, 0, 0) | ||
|
||
def rgb_to_hex(r: int, g: int, b: int) -> str: | ||
|
||
r = max(0, min(255, r)) | ||
g = max(0, min(255, g)) | ||
b = max(0, min(255, b)) | ||
|
||
return f"#{r:02x}{g:02x}{b:02x}" | ||
|
||
print(hex_to_rgb("#ffffff")) | ||
print(hex_to_rgb("ffffff")) | ||
print(hex_to_rgb("#000000")) | ||
print(hex_to_rgb("#fabada")) | ||
print(hex_to_rgb("#cagada")) | ||
print(hex_to_rgb("#fffffff")) | ||
print(hex_to_rgb("#fffff")) | ||
|
||
print(rgb_to_hex(0, 0, 0)) | ||
print(rgb_to_hex(255, 255, 255)) | ||
print(rgb_to_hex(250, 186, 218)) | ||
print(rgb_to_hex(255, 255, -5)) |
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 #38: Las sumas | ||
#### Dificultad: Media | Publicación: 25/09/23 | Corrección: 02/10/23 | ||
|
||
## Enunciado | ||
|
||
``` | ||
/* | ||
* Crea una función que encuentre todas las combinaciones de los números | ||
* de una lista que suman el valor objetivo. | ||
* - La función recibirá una lista de números enteros positivos | ||
* y un valor objetivo. | ||
* - Para obtener las combinaciones sólo se puede usar | ||
* una vez cada elemento de la lista (pero pueden existir | ||
* elementos repetidos en ella). | ||
* - Ejemplo: Lista = [1, 5, 3, 2], Objetivo = 6 | ||
* Soluciones: [1, 5] y [1, 3, 2] (ambas combinaciones suman 6) | ||
* (Sin no existen combinaciones, retornar una lista vacía) | ||
*/ | ||
``` | ||
#### Tienes toda la información extendida sobre los retos de programación semanales en **[retosdeprogramacion.com/semanales2023](https://retosdeprogramacion.com/semanales2023)**. | ||
|
||
Sigue las **[instrucciones](../../README.md)**, consulta las correcciones y aporta la tuya propia utilizando el lenguaje de programación que quieras. | ||
|
||
> Recuerda que cada semana se publica un nuevo ejercicio y se corrige el de la semana anterior en directo desde **[Twitch](https://twitch.tv/mouredev)**. Tienes el horario en la sección "eventos" del servidor de **[Discord](https://discord.gg/mouredev)**. |