RB-Technical-Test/FizzBuzz/Program.cs

94 lines
3.6 KiB
C#
Raw Permalink Normal View History

2020-06-26 12:56:07 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
{
foreach (int number in GetNumbers())
{
//Console.WriteLine("asdsaadas" + MultiplesOfThree.FirstOrDefault(f => f == number.ToString()));
if (MultiplesOfThree.FirstOrDefault(f => f == number.ToString()) != null && MultiplesOfFive.FirstOrDefault(f => f == number.ToString()) != null)
{
Console.WriteLine(GetFizzBuzz());
continue;
}
if (MultiplesOfThree.FirstOrDefault(f => f == number.ToString()) != null)
{
Console.WriteLine(GetFizz());
continue;
}
if (MultiplesOfFive.FirstOrDefault(f => f == number.ToString()) != null)
{
Console.WriteLine(GetBuzz());
continue;
}
Console.WriteLine(number);
}
}
private static readonly List<string> MultiplesOfThree = new List<string> {
"3", "6", "9", "12", "15", "18", "21", "24", "27", "30", "33", "36", "39", "42", "45", "48", "51", "54", "57", "60", "63", "66", "69", "72", "75", "78", "81", "84", "87", "90", "93", "96", "99"
};
private static readonly List<string> MultiplesOfFive = new List<string> {
"5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", "80", "85", "90", "95", "100"
};
static List<int> GetNumbers()
{
List<int> numbers = new List<int>();
while (numbers.Count < 100)
{
Random rand = new Random();
int r = rand.Next(1, 101);
if (numbers.Count == 0)
{
if (r == 1)
numbers.Add(r);
}
else
if (r == numbers[numbers.Count - 1] + 1)
{
numbers.Add(r);
Console.WriteLine(r);
}
}
return numbers;
}
static string GetCharacter(Characters character)
{
if (character.ToString().ToCharArray()[0] > 'E' && character.ToString().ToCharArray()[0] < 'G') return "F";
if (character.ToString().ToCharArray()[0] > 'h' && character.ToString().ToCharArray()[0] < 'j') return "i";
if (character.ToString().ToCharArray()[0] > 'y' && character.ToString().ToCharArray()[0] < 123) return "z";
if (character.ToString().ToCharArray()[0] > 'A' && character.ToString().ToCharArray()[0] < 'C') return "B";
if (character.ToString().ToCharArray()[0] > 't' && character.ToString().ToCharArray()[0] < 'v') return "u";
return "Unknown";
}
static string GetFizz()
{
return GetCharacter(Characters.F) + GetCharacter(Characters.i) + GetCharacter(Characters.z) + GetCharacter(Characters.z);
}
static string GetBuzz()
{
return GetCharacter(Characters.B) + GetCharacter(Characters.u) + GetCharacter(Characters.z) + GetCharacter(Characters.z);
}
static string GetFizzBuzz()
{
return GetCharacter(Characters.F) + GetCharacter(Characters.i) + GetCharacter(Characters.z) + GetCharacter(Characters.z) + GetCharacter(Characters.B) + GetCharacter(Characters.u) + GetCharacter(Characters.z) + GetCharacter(Characters.z);
}
}
enum Characters
{
F, i, z, B, u
}
}