Skip to content

Commit b3e075a

Browse files
committed
✨ Add WeeklyChallenges class and project file for dotNet solutions
1 parent d519497 commit b3e075a

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

weekly-challenges.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
3+
class WeeklyChallenges
4+
{
5+
private class Challenge(string name, Action execute)
6+
{
7+
public string Name { get; } = name;
8+
public Action Execute { get; } = execute;
9+
}
10+
11+
private static readonly Dictionary<string, Challenge> challenges2024 = new() {
12+
{ "00", new Challenge("Sintaxis, variables, tipos de datos y ¡Hola, Mundo!", SintaxisVariables.Execute) },
13+
};
14+
15+
private static readonly Dictionary<int, Dictionary<string, Challenge>> challengeActions = new() {
16+
{ 2024, challenges2024 },
17+
};
18+
19+
20+
static void Main(string[] args)
21+
{
22+
if (args.Length != 2)
23+
{
24+
Console.WriteLine("Por favor, ingresa el año y el número del reto que deseas ejecutar. \nEjemplo: dotnet run 2024 01");
25+
return;
26+
}
27+
28+
if (!int.TryParse(args[0], out var year))
29+
{
30+
Console.WriteLine("El año ingresado no es válido. Asegúrate de ingresar un número.");
31+
return;
32+
}
33+
34+
string challenge = args[1];
35+
36+
ExecuteChallenge(year, challenge);
37+
}
38+
39+
private static void ExecuteChallenge(int year, string challenge)
40+
{
41+
if (challengeActions.TryGetValue(year, out var yearChallenges) &&
42+
yearChallenges.TryGetValue(challenge, out var challengeData))
43+
{
44+
Console.WriteLine($"Ejecutando reto: {challengeData.Name}\n");
45+
challengeData.Execute();
46+
}
47+
else
48+
Console.WriteLine("El reto ingresado no existe.");
49+
}
50+
}

weekly-challenges.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>weekly_challenges</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
</Project>

0 commit comments

Comments
 (0)