Advertisement
Placido_GDD

Don'tGiveMeFive

Jun 5th, 2022
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System.Collections.Generic;  
  2.  
  3. public class Kata
  4. {
  5.   public static int DontGiveMeFive(int start, int end)
  6.   {
  7.     //Generate Range of integers based on input
  8.     //Filter out 5's
  9.     //Return count of remaining integers
  10.    
  11.     List <int> intList = new List<int>();
  12.     int result = 0;
  13.     bool hasFive = false;
  14.     for(int x = start;x < end;x++)
  15.     {
  16.       intList.Add(x);
  17.     }
  18.    
  19.      result = intList.Count;
  20.     for(int i = 0;i < intList.Count;i++)
  21.     {
  22.       hasFive = false;
  23.       string numString = intList[i].ToString();
  24.       char[] numChars = numString.ToCharArray();
  25.       for(int a = 0;a < numChars.Length;a++)
  26.       {
  27.        
  28.         if(numChars[a] == '5')
  29.         {
  30.           hasFive = true;  
  31.         }
  32.       }
  33.       if(hasFive == true)
  34.       {
  35.         result --;
  36.       }
  37.     }
  38.    
  39.    
  40.     return result;
  41.   }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement