Sitemap

Generic Sequence Generators

10 min readSep 15, 2026

--

The target framework: .NET 8

Task Description

Develop a class library that provides generators for sequences of elements of various types. To complete this task, you need to perform the following steps:

1. Generic Sequence Generator Interface

  • Create a generic interface ISequenceGenerator<T>.
  • Define the following properties:
  • Previous of type T, representing the previous element in the sequence.
  • Current of type T, representing the current element in the sequence.
  • Next of type T, representing the next element in the sequence.

2. Generic Sequence Generator Class

  • Create an abstract class SequenceGenerator<T> that implements the ISequenceGenerator<T> interface.
  • Provide a constructor that initializes two first values of the sequence.
  • Implement the properties Previous and Current with appropriate accessors.
  • Define a public property Count, representing the number of elements generated in the sequence. The property should have a public getter and a private setter.
  • Define an abstract method called GetNext() that implements the logic for getting the next element after the Previous and Current elements of a given sequence.

3. Fibonacci Sequence Generator Class

  • Create a class called FibonacciSequenceGenerator that inherits from SequenceGenerator<int>.
  • Provide a constructor that initializes two first values of the sequence.
  • Implement the GetNext() method to generate the next Fibonacci number based on the previous and current values. The Fibonacci sequence starts with two initial values (e.g., 0 and 1), and each subsequent number is the sum of the previous two.

4. Integer Sequence Generator Class

  • Create a class called IntegerSequenceGenerator that inherits from SequenceGenerator<int>.
  • Provide a constructor that initializes two first values of the sequence.
  • Implement the GetNext() method to generate the elements of the sequence based the following rule:

.
Data for tests: { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }, n = 10.

5. Double Sequence Generator Class

  • Create a class called DoubleSequenceGenerator that inherits from SequenceGenerator<double>.
  • Provide a constructor that initializes two first values of the sequence.
  • Implement the GetNext() method to generate the elements of the sequence based the following rule:

Data for tests: {1, 2, 2.5, 3.3, 4.05757575757576, 4.87086926018965, 5.70389834408211, 6.55785277425587, 7.42763417076325, 8.31053343902137}, n = 10.

6. Char Sequence Generator Class

  • Create a class called CharSequenceGenerator that inherits from SequenceGenerator<char>.
  • Provide a constructor that initializes two first values of the sequence.
  • Implement the GetNext() method to generate the elements of the sequence based the following rule:

The formula generates a new character based on the two previous characters, ensuring the result is always within the English alphabet.

Get Erdinç Değirmenci’s stories in your inbox

Join Medium for free to get updates from this writer.

Data for tests: {'A', 'B', 'B', 'C', 'D', 'F', 'I', 'N', 'V', 'I'}, n = 10

7. Generic Sequence Generator Class With Delegate

  • Create a class called DelegateSequenceGenerator<T> that inherits from SequenceGenerator<T> and use a delegate type to implement a generalized generator of the n-first members of a sequence specified by a recurrent formula for elements of type T according to the rule

8. The Solution Class Methods

  • Study the HowToUseCharSequenceGenerator method in the predefined Solution class (available in the Solution text field). This method calls the GetNext method of the CharSequenceGenerator class.
  • Implement the following methods:
  • HowToUseIntegerSequenceGenerator;
  • HowToUseFibonacciSequenceGenerator;
  • HowToUseDoubleSequenceGenerator;
  • HowToUseDelegateSequenceGenerator.
  • To complete this assignment, insert the types and method implementations of the Solution class that you have developed into the Solution text field below. Ensure that all required types are included in the Solution text field, then click Submit to submit your solution.
  • Do not modify the predefined Solution class name or the names of its methods.
  • For a smoother development experience, you may copy the task skeleton into an IDE (Visual Studio, Visual Studio Code, etc.) or use an online compiler like .NET Fiddle.
  • The task has a fixed execution time. Any changes made after the time expires will be ignored.
  • Your solution will be tested against both visible and hidden test cases. Visible tests verify correctness based on expected input-output pairs (see table below) and hidden enforce constraints such as required types, method names, class structure, access modifiers, return types, and the presence of necessary constructors or properties.
  • Please note that when checking the tests of this task by the platform, you will see a message about only one of the possible failed tests, even if there is more than one.
  • You can use the following archive of the VS solution with the NUnit test project to be able to test your solution locally before submitting it to Autocode.
Press enter or click to view image in full size
// !!! Predefined class name 'Solution' and method names !!!
// !!! DO NOT CHANGE !!!

public static class Solution
{
/// <summary>
/// Generates a sequence of characters using the specified count, previous character, and current character.
/// This method will call the `CharSequenceGenerator` to generate the sequence.
/// </summary>
/// <param name="count">The number of characters to generate in the sequence.</param>
/// <param name="previous">The previous character in the sequence.</param>
/// <param name="current">The current character in the sequence.</param>
/// <returns>A list of characters representing the generated sequence.</returns>
public static IList<char> HowToUseCharSequenceGenerator(int count, char previous, char current)
{
ISequenceGenerator<char> generator = new CharSequenceGenerator(previous, current);

var sequence = new List<char> { generator.Previous, generator.Current };

for (int i = 1; i <= count; i++)
{
sequence.Add(generator.Next);
}

return sequence;
}

/// <summary>
/// Generates a sequence of integers using the specified count, previous integer, and current integer.
/// This method will call the `IntegerSequenceGenerator` to generate the sequence.
/// </summary>
/// <param name="count">The number of integers to generate in the sequence.</param>
/// <param name="previous">The previous integer in the sequence.</param>
/// <param name="current">The current integer in the sequence.</param>
/// <returns>A list of integers representing the generated sequence.</returns>
public static IList<int> HowToUseIntegerSequenceGenerator(int count, int previous, int current)
{
// Add your code here similar to the `HowToUseCharSequenceGenerator` method.

throw new NotImplementedException("HowToUseIntegerSequenceGenerator method is not implemented.");
}

/// <summary>
/// Generates a sequence of integers using the specified count, previous integer, and current integer.
/// This method will call the `FibonacciSequenceGenerator` to generate the sequence.
/// </summary>
/// <param name="count">The number of integers to generate in the sequence.</param>
/// <param name="previous">The previous integer in the sequence.</param>
/// <param name="current">The current integer in the sequence.</param>
/// <returns>A list of integers representing the generated sequence.</returns>
public static IList<int> HowToUseFibonacciSequenceGenerator(int count, int previous, int current)
{
// Add your code here similar to the `HowToUseCharSequenceGenerator` method.

throw new NotImplementedException("HowToUseFibonacciSequenceGenerator method is not implemented.");
}

/// <summary>
/// Generates a sequence of doubles using the specified count, previous double, and current double.
/// This method will call the `DoubleSequenceGenerator` to generate the sequence.
/// </summary>
/// <param name="count">The number of doubles to generate in the sequence.</param>
/// <param name="previous">The previous double in the sequence.</param>
/// <param name="current">The current double in the sequence.</param>
/// <returns>A list of doubles representing the generated sequence.</returns>
public static IList<double> HowToUseDoubleSequenceGenerator(int count, double previous, double current)
{
// Add your code here similar to the `HowToUseCharSequenceGenerator` method.

throw new NotImplementedException("HowToUseDoubleSequenceGenerator method is not implemented.");
}


/// <summary>
/// Generates a sequence of elements using the specified count, previous element, current element, and a delegate function.
/// This method will call the `DelegateSequenceGenerator` to generate the sequence.
/// </summary>
/// <typeparam name="T">The type of elements in the sequence.</typeparam>
/// <param name="count">The number of elements to generate in the sequence.</param>
/// <param name="previous">The previous element in the sequence.</param>
/// <param name="current">The current element in the sequence.</param>
/// <param name="nextFunc">The delegate function to calculate the next element in the sequence.</param>
/// <returns>A list of elements representing the generated sequence.</returns>
public static IList<T> HowToUseDelegateSequenceGenerator<T>(int count, T previous, T current,
Func<T, T, T> nextFunc)
{
// Add your code here similar to the `HowToUseCharSequenceGenerator` method.

throw new NotImplementedException("HowToUseDelegateSequenceGenerator method is not implemented.");
}
}

// TODO: Implement the ISequenceGenerator interface.

// TODO: Implement the SequenceGenerator class.

// TODO: Implement the CharSequenceGenerator class.

// TODO: Implement the IntegerSequenceGenerator class.

// TODO: Implement the DelegateSequenceGenerator class.

// TODO: Implement the DoubleSequenceGeneratorD class.

// TODO: Implement the FibonacciSequenceGenerator class.
// !!! Predefined class name 'Solution' and method names !!!
// !!! DO NOT CHANGE !!!

public static class Solution
{
/// <summary>
/// Generates a sequence of characters using the specified count, previous character, and current character.
/// This method will call the `CharSequenceGenerator` to generate the sequence.
/// </summary>
/// <param name="count">The number of characters to generate in the sequence.</param>
/// <param name="previous">The previous character in the sequence.</param>
/// <param name="current">The current character in the sequence.</param>
/// <returns>A list of characters representing the generated sequence.</returns>
public static IList<char> HowToUseCharSequenceGenerator(int count, char previous, char current)
{
ISequenceGenerator<char> generator = new CharSequenceGenerator(previous, current);

var sequence = new List<char> { generator.Previous, generator.Current };

for (int i = 1; i <= count; i++)
{
sequence.Add(generator.Next);
}

return sequence;
}

/// <summary>
/// Generates a sequence of integers using the specified count, previous integer, and current integer.
/// This method will call the `IntegerSequenceGenerator` to generate the sequence.
/// </summary>
/// <param name="count">The number of integers to generate in the sequence.</param>
/// <param name="previous">The previous integer in the sequence.</param>
/// <param name="current">The current integer in the sequence.</param>
/// <returns>A list of integers representing the generated sequence.</returns>
public static IList<int> HowToUseIntegerSequenceGenerator(int count, int previous, int current)
{
// Add your code here similar to the `HowToUseCharSequenceGenerator` method.
ISequenceGenerator<int> generator = new IntegerSequenceGenerator(previous, current);

var sequence = new List<int> { generator.Previous, generator.Current };


for (int i = 1; i <= count; i++)
{
sequence.Add(generator.Next);
}


return sequence;
}

/// <summary>
/// Generates a sequence of integers using the specified count, previous integer, and current integer.
/// This method will call the `FibonacciSequenceGenerator` to generate the sequence.
/// </summary>
/// <param name="count">The number of integers to generate in the sequence.</param>
/// <param name="previous">The previous integer in the sequence.</param>
/// <param name="current">The current integer in the sequence.</param>
/// <returns>A list of integers representing the generated sequence.</returns>
public static IList<int> HowToUseFibonacciSequenceGenerator(int count, int previous, int current)
{
// Add your code here similar to the `HowToUseCharSequenceGenerator` method.

ISequenceGenerator<int> generator = new FibonacciSequenceGenerator(previous, current);

var sequence = new List<int> { generator.Previous, generator.Current };

for (int i = 1; i < count; i++)
{

sequence.Add(generator.Next);
}

return sequence;
}

/// <summary>
/// Generates a sequence of doubles using the specified count, previous double, and current double.
/// This method will call the `DoubleSequenceGenerator` to generate the sequence.
/// </summary>
/// <param name="count">The number of doubles to generate in the sequence.</param>
/// <param name="previous">The previous double in the sequence.</param>
/// <param name="current">The current double in the sequence.</param>
/// <returns>A list of doubles representing the generated sequence.</returns>
public static IList<double> HowToUseDoubleSequenceGenerator(int count, double previous, double current)
{
// Add your code here similar to the `HowToUseCharSequenceGenerator` method.

ISequenceGenerator<double> generator = new DoubleSequenceGenerator(previous, current);

var sequence = new List<double> { generator.Previous, generator.Current };

for (int i = 1; i < count; i++)
{

sequence.Add(generator.Next);
}

return sequence;
}


/// <summary>
/// Generates a sequence of elements using the specified count, previous element, current element, and a delegate function.
/// This method will call the `DelegateSequenceGenerator` to generate the sequence.
/// </summary>
/// <typeparam name="T">The type of elements in the sequence.</typeparam>
/// <param name="count">The number of elements to generate in the sequence.</param>
/// <param name="previous">The previous element in the sequence.</param>
/// <param name="current">The current element in the sequence.</param>
/// <param name="nextFunc">The delegate function to calculate the next element in the sequence.</param>
/// <returns>A list of elements representing the generated sequence.</returns>
public static IList<T> HowToUseDelegateSequenceGenerator<T>(int count, T previous, T current,
Func<T, T, T> nextFunc)
{
// Add your code here similar to the `HowToUseCharSequenceGenerator` method.

ISequenceGenerator<T> generator =new DelegateSequenceGenerator<T>(previous, current, nextFunc);

var sequence = new List<T> { generator.Previous, generator.Current };

for (int i = 1; i < count; i++)
{
sequence.Add(generator.Next);
}

return sequence;
}
}

// TODO: Implement the ISequenceGenerator interface.
public interface ISequenceGenerator<T>
{
T Previous { get; }
T Current { get; }
T Next { get; }
}


// TODO: Implement the SequenceGenerator class.

public abstract class SequenceGenerator<T> : ISequenceGenerator<T>
{
protected T _previous;
protected T _current;

protected SequenceGenerator(T previous, T current)
{
_previous = previous;
_current = current;
Count = 2;
}

public T Previous => _previous;
public T Current => _current;

public int Count { get; private set; }

protected abstract T GetNext();

public T Next
{
get
{
T next = GetNext();
_previous = _current;
_current = next;
Count++;
return next;
}
}
}


// TODO: Implement the CharSequenceGenerator class.
public class CharSequenceGenerator : SequenceGenerator<char>
{
public CharSequenceGenerator(char previous, char current)
: base(previous, current)
{
}

protected override char GetNext()
{
int a = _previous - 'A';
int b = _current - 'A';
int next = (a + b) % 26;
return (char)('A' + next);
}
}
// TODO: Implement the IntegerSequenceGenerator class.
public class IntegerSequenceGenerator : SequenceGenerator<int>
{
public IntegerSequenceGenerator(int previous, int current)
: base(previous, current)
{
}

protected override int GetNext()
{
return _current * 2;
}
}
// TODO: Implement the DelegateSequenceGenerator class.
public class DelegateSequenceGenerator<T> : SequenceGenerator<T>
{
private readonly Func<T, T, T> _nextFunc;

public DelegateSequenceGenerator(T previous, T current, Func<T, T, T> nextFunc)
: base(previous, current)
{
_nextFunc = nextFunc;
}

protected override T GetNext()
{
return _nextFunc(_previous, _current);
}
}
// TODO: Implement the DoubleSequenceGeneratorD class.
public class DoubleSequenceGenerator : SequenceGenerator<double>
{
public DoubleSequenceGenerator(double previous, double current)
: base(previous, current)
{
}

protected override double GetNext()
{
return _current + (_current - _previous) * 0.65;
}


}
// TODO: Implement the FibonacciSequenceGenerator class.
public class FibonacciSequenceGenerator : SequenceGenerator<int>
{
public FibonacciSequenceGenerator(int previous, int current)
: base(previous, current)
{
}

protected override int GetNext()
{
return _previous + _current;
}
}

--

--