Skip to content

Commit 9909d64

Browse files
committed
Added class and test method for Fibonacci Checker code challenge.
Updated challenge list text files
1 parent af6d06d commit 9909d64

File tree

6 files changed

+76
-1
lines changed

6 files changed

+76
-1
lines changed

Coderbyte_CSharp/1 Easy Challenges/EasyChallenges.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Challenge: C# Date: Class
55
Alphabet Soup 02/10/2021 AlphabetSorter
66
ArithGeo 02/10/2021 MathSequence
77
Check Numbers 02/10/2021 NumberCheck
8+
Fibonacci Checker 02/24/2021 MathFibonacci
89
Find Intersection 02/11/2021 StringIntersection
910
First Factorial 02/22/2021 Factorial
1011
First Reverse 02/22/2021 StringReverse
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Coderbyte_CSharp._Easy_Challenges
8+
{
9+
class MathFibonacci
10+
{
11+
public string FibonacciChecker(int num)
12+
{
13+
string result = String.Empty;
14+
bool isFibonacci = false;
15+
16+
isFibonacci = IsValidFibonacci(1, 1, num);
17+
18+
result = (isFibonacci) ? "yes" : "no";
19+
20+
return result;
21+
}
22+
23+
protected bool IsValidFibonacci(int x, int y, int num)
24+
{
25+
bool isFibonacci = false;
26+
27+
if (num == 0 || num == 1)
28+
{
29+
isFibonacci = true;
30+
}
31+
32+
else if (x + y == num)
33+
{
34+
isFibonacci = true;
35+
}
36+
37+
else if (x + y < num)
38+
{
39+
isFibonacci = IsValidFibonacci(x + y, x, num);
40+
}
41+
42+
else
43+
{
44+
isFibonacci = false;
45+
}
46+
47+
return isFibonacci;
48+
}
49+
}
50+
}

Coderbyte_CSharp/2 Medium Challenges/MediumChallenges.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Challenge: C# Date: Class:
55
Consecutive 02/12/2021 ConsecutiveNumbers
66
K Unique Chars 02/12/2021 StringUniqueSubstring
77
Number Encoding 02/12/2021 NumberEncoder
8+
Preorder Traversal
89
Prime Mover 02/12/2021 PrimeNumber
910
Run Length 02/15/2021 StringCompression
1011
String Reduction 02/15/2021 StringReducer

Coderbyte_CSharp/Coderbyte_CSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<Compile Include="1 Easy Challenges\ChangeLetter.cs" />
4848
<Compile Include="1 Easy Challenges\ExponentTwo.cs" />
4949
<Compile Include="1 Easy Challenges\Factorial.cs" />
50+
<Compile Include="1 Easy Challenges\MathFibonacci.cs" />
5051
<Compile Include="1 Easy Challenges\MathProduct.cs" />
5152
<Compile Include="1 Easy Challenges\MathSequence.cs" />
5253
<Compile Include="1 Easy Challenges\MedianMovement.cs" />

Coderbyte_CSharp/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static void Main(string[] args)
3232
tc.Test_MovingMedian();
3333
tc.Test_QuestionsMarks();
3434
tc.Test_RemoveBrackets();
35+
tc.Test_FibonacciChecker();
3536

3637
// Medium
3738
Console.WriteLine("Medium Code Challenges:");

Coderbyte_CSharp/TestChallenge.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5-
5+
using Coderbyte_CSharp._Easy_Challenges;
66
using Coderbyte_CSharp.Easy_Challenges;
77
using Coderbyte_CSharp.Medium_Challenges;
88
using Coderbyte_CSharp.Hard_Challenges;
@@ -345,6 +345,27 @@ public void Test_RemoveBrackets()
345345
Console.WriteLine();
346346
}
347347

348+
public void Test_FibonacciChecker()
349+
{
350+
MathFibonacci fibonacci = new MathFibonacci();
351+
Console.WriteLine("Fibonacci Checker:");
352+
353+
int num = 5;
354+
Console.WriteLine("Input: {0}", num);
355+
Console.WriteLine("Output: {0}", fibonacci.FibonacciChecker(num));
356+
Console.WriteLine();
357+
358+
num = 34;
359+
Console.WriteLine("Input: {0}", num);
360+
Console.WriteLine("Output: {0}", fibonacci.FibonacciChecker(num));
361+
Console.WriteLine();
362+
363+
num = 54;
364+
Console.WriteLine("Input: {0}", num);
365+
Console.WriteLine("Output: {0}", fibonacci.FibonacciChecker(num));
366+
Console.WriteLine();
367+
}
368+
348369

349370
#endregion
350371

0 commit comments

Comments
 (0)