Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solucion en C# #277

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/*
* Reto #43
Expand Down Expand Up @@ -35,3 +39,116 @@ import Foundation
* https://retosdeprogramacion.com/semanales2022.
*
*/

namespace Reto43
{
internal class Program
{
static void Main(string[] args)
{
string dulces = Halloween.TrucoOTrato(new List<Persona>
{
new Persona(){Nombre = "Luis",Edad = 1,Altura = 49},
//8+8+7

}, new Trato());
Console.OutputEncoding = Encoding.UTF8;
Console.WriteLine(dulces);
Console.WriteLine(dulces.Length / 2);
Console.ReadKey();

}
}

internal class Truco : RegaloHalloween
{
protected override string[] _elementos { get; set; } = new string[] { "🎃", "👻", "💀", "🕷", "🕸", "🦇" };

protected override int ObtenerPorAltutra(List<Persona> personas)
{
return personas.Sum(i => i.Altura) / 100;
}

protected override int ObtenerPorAños(List<Persona> personas)
{
return personas.Where(i => i.Edad % 2 == 0).Count() * 2;
}

protected override int ObtenerPorNombre(List<Persona> personas)
{
return personas.Sum(i => i.Nombre.Length) / 2;
}
}

internal abstract class RegaloHalloween
{
protected abstract string[] _elementos { get; set; }

protected abstract int ObtenerPorNombre(List<Persona> personas);
protected abstract int ObtenerPorAños(List<Persona> personas);
protected abstract int ObtenerPorAltutra(List<Persona> personas);

public string TrucoOTrato(List<Persona> personas)
{
string resultado = "";
resultado += ObtenerDulce(ObtenerPorNombre(personas));
resultado += ObtenerDulce(ObtenerPorAños(personas));
resultado += ObtenerDulce(ObtenerPorAltutra(personas));
return resultado;
}

private string ObtenerDulce(int num)
{
string resultado = string.Empty;
Random random = new Random();
for (int i = 0; i < num; i++)
{
int index = random.Next(0, _elementos.Length);
resultado += _elementos[index];
}
return resultado;
}
}

internal class Trato : RegaloHalloween
{
protected override string[] _elementos { get; set; } = new string[] { "🍰", "🍬", "🍡", "🍭", "🍪", "🍫", "🧁", "🍩" };

private int ObtenerDuclcesPorAlutraOAños(IEnumerable<int> personas, int limiteDulces, int porcada, int numeroDeDulcesADarPorCada)
{
return personas.Sum((i) =>
{
return (i / porcada) * numeroDeDulcesADarPorCada > limiteDulces ? limiteDulces : (i / porcada) * numeroDeDulcesADarPorCada;
});
}

protected override int ObtenerPorAltutra(List<Persona> personas)
{
return ObtenerDuclcesPorAlutraOAños(personas.Select(i => i.Altura), 6, 50, 2);
}

protected override int ObtenerPorAños(List<Persona> personas)
{
return ObtenerDuclcesPorAlutraOAños(personas.Select(i => i.Edad), 3, 3, 1);
}

protected override int ObtenerPorNombre(List<Persona> personas)
{
return personas.Sum(i => i.Nombre.Length);
}
}

internal class Halloween
{
public static string TrucoOTrato(List<Persona> personas, RegaloHalloween trucoTrato)
{
return trucoTrato.TrucoOTrato(personas);
}
}
internal class Persona
{
public string Nombre { get; set; }
public int Edad { get; set; }
public int Altura { get; set; }
}
}