-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFizzBuzzer.cs
51 lines (48 loc) · 1.13 KB
/
FizzBuzzer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
namespace FizzBuzz;
public class FizzBuzzer {
public string FizzBuzz(int i) {
var result = "";
if(IsDivisibleBy(i, 3))
{
result += "Fizz";
}
if(IsDivisibleBy(i,5))
{
result += "Buzz";
}
if(IsDivisibleBy(i,7))
{
result += "Bang";
}
if(IsDivisibleBy(i,11))
{
result = "Bong";
}
if(IsDivisibleBy(i,13))
{
int BIndex = result.IndexOf("B");
if (result.IndexOf("B") == -1)
{
result += "Fezz";
}
else
{
if (BIndex == 0)
{
result = "Fezz" + result.Substring(BIndex);
} else
{
result = result.Substring(0,BIndex) + "Fezz" + result.Substring(BIndex);
}
}
}
if (result == "")
{
result = i.ToString();
}
return result;
}
private bool IsDivisibleBy(int num, int denom) {
return num % denom == 0;
}
}