File tree Expand file tree Collapse file tree 6 files changed +76
-1
lines changed Expand file tree Collapse file tree 6 files changed +76
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ Challenge: C# Date: Class
5
5
Alphabet Soup 02/10/2021 AlphabetSorter
6
6
ArithGeo 02/10/2021 MathSequence
7
7
Check Numbers 02/10/2021 NumberCheck
8
+ Fibonacci Checker 02/24/2021 MathFibonacci
8
9
Find Intersection 02/11/2021 StringIntersection
9
10
First Factorial 02/22/2021 Factorial
10
11
First Reverse 02/22/2021 StringReverse
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ Challenge: C# Date: Class:
5
5
Consecutive 02/12/2021 ConsecutiveNumbers
6
6
K Unique Chars 02/12/2021 StringUniqueSubstring
7
7
Number Encoding 02/12/2021 NumberEncoder
8
+ Preorder Traversal
8
9
Prime Mover 02/12/2021 PrimeNumber
9
10
Run Length 02/15/2021 StringCompression
10
11
String Reduction 02/15/2021 StringReducer
Original file line number Diff line number Diff line change 47
47
<Compile Include =" 1 Easy Challenges\ChangeLetter.cs" />
48
48
<Compile Include =" 1 Easy Challenges\ExponentTwo.cs" />
49
49
<Compile Include =" 1 Easy Challenges\Factorial.cs" />
50
+ <Compile Include =" 1 Easy Challenges\MathFibonacci.cs" />
50
51
<Compile Include =" 1 Easy Challenges\MathProduct.cs" />
51
52
<Compile Include =" 1 Easy Challenges\MathSequence.cs" />
52
53
<Compile Include =" 1 Easy Challenges\MedianMovement.cs" />
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ static void Main(string[] args)
32
32
tc . Test_MovingMedian ( ) ;
33
33
tc . Test_QuestionsMarks ( ) ;
34
34
tc . Test_RemoveBrackets ( ) ;
35
+ tc . Test_FibonacciChecker ( ) ;
35
36
36
37
// Medium
37
38
Console . WriteLine ( "Medium Code Challenges:" ) ;
Original file line number Diff line number Diff line change 2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
4
using System . Text ;
5
-
5
+ using Coderbyte_CSharp . _Easy_Challenges ;
6
6
using Coderbyte_CSharp . Easy_Challenges ;
7
7
using Coderbyte_CSharp . Medium_Challenges ;
8
8
using Coderbyte_CSharp . Hard_Challenges ;
@@ -345,6 +345,27 @@ public void Test_RemoveBrackets()
345
345
Console . WriteLine ( ) ;
346
346
}
347
347
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
+
348
369
349
370
#endregion
350
371
You can’t perform that action at this time.
0 commit comments