mirror of
https://github.com/onyx-and-iris/Lottery.git
synced 2026-02-26 22:39:10 +00:00
rename Limits record to Sample
This commit is contained in:
parent
72e7728e8f
commit
481925d210
@ -3,16 +3,16 @@
|
||||
internal class Generator
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple algorithm for generating a list of unique numbers of Limits.Count size
|
||||
/// Simple algorithm for generating a list of unique numbers of sample.Count size.
|
||||
/// </summary>
|
||||
/// <param name="limits">Defines the amount of numbers to generate, the min and max values</param>
|
||||
/// <param name="sample">Defines the sample size as well as the upper and lower bounds.</param>
|
||||
/// <returns>Numbers are returned as a sorted set.</returns>
|
||||
public static SortedSet<int> Generate(Limits limits)
|
||||
public static SortedSet<int> Generate(Sample sample)
|
||||
{
|
||||
List<int> candidates = [.. Enumerable.Range(limits.Lower, limits.Upper)];
|
||||
List<int> candidates = [.. Enumerable.Range(sample.Lower, sample.Upper)];
|
||||
SortedSet<int> numbers = [];
|
||||
|
||||
for (int i = 0; i < limits.Count; i++)
|
||||
for (int i = 0; i < sample.Count; i++)
|
||||
{
|
||||
int RandomIndex = Random.Shared.Next(candidates.Count);
|
||||
numbers.Add(candidates[RandomIndex]);
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
namespace Lottery
|
||||
{
|
||||
internal record Limits(int Count, int Lower, int Upper);
|
||||
internal record Sample(int Lower, int Upper, int Count);
|
||||
|
||||
/// <summary>
|
||||
/// Abstract base class for lotteries.
|
||||
/// Limits property must be overridden.
|
||||
/// Sample property must be overridden.
|
||||
/// </summary>
|
||||
internal abstract class Lottery
|
||||
{
|
||||
protected virtual Limits Limits => throw new NotImplementedException();
|
||||
public virtual string Play() => $"Numbers: {string.Join(", ", Generator.Generate(Limits))}";
|
||||
protected virtual Sample Sample => throw new NotImplementedException();
|
||||
public virtual string Play() => $"Numbers: {string.Join(", ", Generator.Generate(Sample))}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -18,24 +18,24 @@
|
||||
/// </summary>
|
||||
internal class LottoLottery : Lottery
|
||||
{
|
||||
protected override Limits Limits { get; } = new(Count: 6, Lower: 1, Upper: 59);
|
||||
protected override Sample Sample { get; } = new(Lower: 1, Upper: 59, Count: 6);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract base class for Lotteries with Special values.
|
||||
/// It subclasses Lottery.
|
||||
/// SpecialLimits and SpecialIdentifier properties must be overridden.
|
||||
/// SpecialSample and SpecialIdentifier properties must be overridden.
|
||||
/// </summary>
|
||||
internal abstract class LotteryWithSpecial : Lottery
|
||||
{
|
||||
protected virtual Limits SpecialLimits => throw new NotImplementedException();
|
||||
protected virtual Sample SpecialSample => throw new NotImplementedException();
|
||||
protected virtual string SpecialIdentifier => throw new NotImplementedException();
|
||||
|
||||
public override string Play()
|
||||
{
|
||||
return string.Join("\n", [
|
||||
$"Numbers: {string.Join(", ", Generator.Generate(Limits))}",
|
||||
$"{SpecialIdentifier}: {string.Join(", ", Generator.Generate(SpecialLimits))}",
|
||||
$"Numbers: {string.Join(", ", Generator.Generate(Sample))}",
|
||||
$"{SpecialIdentifier}: {string.Join(", ", Generator.Generate(SpecialSample))}",
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -46,8 +46,8 @@
|
||||
/// </summary>
|
||||
internal class EuroMillionsLottery : LotteryWithSpecial
|
||||
{
|
||||
protected override Limits Limits { get; } = new(Count: 5, Lower: 1, Upper: 50);
|
||||
protected override Limits SpecialLimits { get; } = new(Count: 2, Lower: 1, Upper: 12);
|
||||
protected override Sample Sample { get; } = new(Lower: 1, Upper: 50, Count: 5);
|
||||
protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 12, Count: 2);
|
||||
protected override string SpecialIdentifier => "Lucky Stars";
|
||||
}
|
||||
|
||||
@ -57,8 +57,8 @@
|
||||
/// </summary>
|
||||
internal class SetForLifeLottery : LotteryWithSpecial
|
||||
{
|
||||
protected override Limits Limits { get; } = new(Count: 5, Lower: 1, Upper: 47);
|
||||
protected override Limits SpecialLimits { get; } = new(Count: 1, Lower: 1, Upper: 10);
|
||||
protected override Sample Sample { get; } = new(Lower: 1, Upper: 47, Count: 5);
|
||||
protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 10, Count: 1);
|
||||
protected override string SpecialIdentifier => "Life Ball";
|
||||
}
|
||||
|
||||
@ -68,8 +68,8 @@
|
||||
/// </summary>
|
||||
internal class ThunderballLottery : LotteryWithSpecial
|
||||
{
|
||||
protected override Limits Limits { get; } = new(Count: 5, Lower: 1, Upper: 39);
|
||||
protected override Limits SpecialLimits { get; } = new(Count: 1, Lower: 1, Upper: 14);
|
||||
protected override Sample Sample { get; } = new(Lower: 1, Upper: 39, Count: 5);
|
||||
protected override Sample SpecialSample { get; } = new(Lower: 1, Upper: 14, Count: 1);
|
||||
protected override string SpecialIdentifier => "Thunderball";
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user