Created
May 4, 2023 16:47
-
-
Save Kalkwst/3a538a430106ab6512d291b6c54e7015 to your computer and use it in GitHub Desktop.
FRANKENSTEIN: Fully Realized And Needlessly Komplex Extension-based Numerical Sequence Transformation Engine Involving a Number Builder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
RandomNumberBuilder builder = new RandomNumberBuilder(1, 10); | |
List<int> numbers = builder.Build(10); | |
// Display the original array | |
Console.WriteLine("Original array:"); | |
numbers.DisplayNumberedItems(); | |
Func<int, Func<int, int>> evenTransform = (n) => (m) => m * 2; | |
Func<int, Func<int, int>> oddTransform = (n) => (m) => m + 5; | |
Func<int, Func<int, int>> replaceTransform = (n) => (m) => m > 10 ? 1 : m; | |
Func<int, Func<int, int>> transformNumber = (n) => | |
{ | |
if (n % 2 == 0) | |
{ | |
return evenTransform(n); | |
} | |
else | |
{ | |
return oddTransform(n); | |
} | |
}; | |
List<int> transformedNumbers = numbers.Select(n => | |
replaceTransform(n)(n % 2 == 0 ? evenTransform(n)(n) : oddTransform(n)(n)) | |
).ToList(); | |
Console.WriteLine("Transformed numbers:"); | |
transformedNumbers.DisplayNumberedItems(); | |
} | |
class RandomNumberBuilder | |
{ | |
private int _min; | |
private int _max; | |
private Random _random; | |
public RandomNumberBuilder(int min, int max) | |
{ | |
_min = min; | |
_max = max; | |
_random = new Random(); | |
} | |
public List<int> Build(int count) | |
{ | |
List<int> numbers = new List<int>(); | |
for (int i = 0; i < count; i++) | |
{ | |
int randomNum = _random.Next(_min, _max + 1); | |
numbers.Add(randomNum); | |
} | |
return numbers; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class IEnumerableExtensions | |
{ | |
public static void DisplayNumberedItems(this IEnumerable<int> numbers) | |
{ | |
int count = 1; | |
foreach (int num in numbers) | |
{ | |
Console.WriteLine($"{GetNumberPrefix(count)}: {num}"); | |
count++; | |
} | |
} | |
private static string GetNumberPrefix(int count) | |
{ | |
switch (count) | |
{ | |
case 1: | |
return "first"; | |
case 2: | |
return "second"; | |
case 3: | |
return "third"; | |
default: | |
return $"{count}th"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment