Implemented the functions

This commit is contained in:
MarcUs7i 2025-04-11 17:40:42 +02:00
parent 2d9718e247
commit 5ebee894e7
2 changed files with 73 additions and 17 deletions

View file

@ -4,31 +4,61 @@ namespace DigitSequence;
public sealed class DigitEnumerator : IEnumerator<int> public sealed class DigitEnumerator : IEnumerator<int>
{ {
// TODO private int _divisor;
//private readonly int _number; private bool _started;
private readonly int _number;
/// <summary>
/// The constructor for <see cref="DigitEnumerator"/>
/// </summary>
/// <param name="number">The number</param>
public DigitEnumerator(int number) public DigitEnumerator(int number)
{ {
// TODO _number = Math.Abs(number);
} }
/// <summary>
/// Moves to the next position
/// Default is invalid
/// </summary>
/// <returns>True, if the move was successful, false otherwise</returns>
public bool MoveNext() public bool MoveNext()
{ {
// TODO if (!_started)
return false; {
_started = true;
_divisor = (int)Math.Pow(10, (int)Math.Log10(_number));
return _divisor >= 0;
}
_divisor /= 10;
return _divisor > 0;
} }
/// <summary>
/// Resets the current position
/// </summary>
public void Reset() public void Reset()
{ {
// TODO _started = false;
_divisor = 0;
} }
public int Current => -1; // TODO /// <summary>
/// Value of the current position
/// </summary>
public int Current => _divisor > 0 ? (_number / _divisor) % 10 : 0;
object IEnumerator.Current => null!; // TODO /// <summary>
/// IEnumerator type for <seealso cref="Current"/>
/// </summary>
object IEnumerator.Current => Current;
/// <summary>
/// Disposes resources
/// </summary>
public void Dispose() public void Dispose()
{ {
// TODO ? // TODON'T! it doesn't seem that there is anything that has the need to be disposed
} }
} }

View file

@ -4,18 +4,44 @@ namespace DigitSequence;
public sealed class Digits(int number) : IEnumerable<int>, IComparable<Digits> public sealed class Digits(int number) : IEnumerable<int>, IComparable<Digits>
{ {
// TODO private readonly int _number = Math.Abs(number);
//private readonly int _number;
/// <summary>
/// Compares to another digit
/// </summary>
/// <param name="other">The other digit</param>
/// <returns>The default compared value</returns>
public int CompareTo(Digits? other) public int CompareTo(Digits? other)
{ {
// TODO if (other == null)
return -1; {
return 1;
}
if (ReferenceEquals(this, other))
{
return 0;
}
return _number.CompareTo(other._number);
} }
public IEnumerator<int> GetEnumerator() => null!; // TODO /// <summary>
/// Gets the enumerator of type <see cref="int"/>
/// </summary>
/// <returns>The <see cref="IEnumerator"/> of type <see cref="int"/></returns>
public IEnumerator<int> GetEnumerator() => new DigitEnumerator(number);
IEnumerator IEnumerable.GetEnumerator() => null!; // TODO /// <summary>
/// Gets the enumerator as an <see cref="object"/> of type <see cref="IEnumerator"/>
/// </summary>
/// <returns>The <see cref="IEnumerator"/></returns>
// I'm gonna be a wikipedia author with that many references xD
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public override string ToString() => null!; // TODO /// <summary>
/// The overriden Method to get the <see cref="string"/> representation of the current object
/// </summary>
/// <returns>The values of <see cref="Digits"/> in a <see cref="string"/> format</returns>
public override string ToString() => _number.ToString();
} }