Ad
Code
Diff
  • using System;
    using System.Linq;
    
    public class ArtihmeticParser
    {
      //use a Stack for 
      
      public static int Evaluate(string input)
      {     // add function to remove white spaces pretty sure this doesn't remove whitespace
        string trimmed = String.Concat(input.Where(c => !Char.IsWhiteSpace(c)));
        return input.Split("+").Select(EvaluateProduct).Aggregate(0,(a,b) => a+b);
      }
      
      private static int EvaluateProduct(string input)
      {
        string trimmed = String.Concat(input.Where(c => !Char.IsWhiteSpace(c)));
        return input.Split("*").Select(EvaluateInteger).Aggregate(1,(a,b) => a*b);
      }
      
     
      //should be able to subtract and divide 
      public static int EvaluateSubtraction(string input)
      {
        return input.Split("-").Select(EvaluateInteger).Aggregate(0,(a,b) => a-b);
      }
      
      private static int EvaluateDivision(string input)
      {
        return input.Split("/").Select(EvaluateInteger).Aggregate(1,(a,b) => a/b);
      
      }
      
      
      
      private static int EvaluateInteger(string input)
      {
        return int.Parse(input);
      }
      //code for whitepsace that doesn't work smh
      //public static string TrimWhiteSpace(string whiteSpace)
      //{
      //  return string.Trim(whiteSpace); 
      //}
    
    }
    
    
    • using System;
    • using System.Linq;
    • public class ArtihmeticParser
    • {
    • //use a Stack for
    • public static int Evaluate(string input)
    • {
    • { // add function to remove white spaces pretty sure this doesn't remove whitespace
    • string trimmed = String.Concat(input.Where(c => !Char.IsWhiteSpace(c)));
    • return input.Split("+").Select(EvaluateProduct).Aggregate(0,(a,b) => a+b);
    • }
    • private static int EvaluateProduct(string input)
    • {
    • string trimmed = String.Concat(input.Where(c => !Char.IsWhiteSpace(c)));
    • return input.Split("*").Select(EvaluateInteger).Aggregate(1,(a,b) => a*b);
    • }
    • //should be able to subtract and divide
    • public static int EvaluateSubtraction(string input)
    • {
    • return input.Split("-").Select(EvaluateInteger).Aggregate(0,(a,b) => a-b);
    • }
    • private static int EvaluateDivision(string input)
    • {
    • return input.Split("/").Select(EvaluateInteger).Aggregate(1,(a,b) => a/b);
    • }
    • private static int EvaluateInteger(string input)
    • {
    • return int.Parse(input);
    • }
    • }
    • //code for whitepsace that doesn't work smh
    • //public static string TrimWhiteSpace(string whiteSpace)
    • //{
    • // return string.Trim(whiteSpace);
    • //}
    • }
Code
Diff
  • public class Kata {
      public static boolean[] populateBathroom(boolean[] urinals, int numOfPeople) { 
         //Implement the urinal problem, described as "given x number of people walking 
         //into a bathroom that contains y number of urinals, describe the optimate
         //placement of people so that none is standing next to the other"
         //In this case, the urinals are represented by a boolean array with 
         //true representing a person at a urinal, and false meaning the urinal is empty
        int y = 0 
          if ( y == 3 ) {
            idk how to solve this 
          }
        
        
        return new boolean[] {true, false, true};
      }
    }
    • public class Kata {
    • public static boolean[] populateBathroom(boolean[] urinals, int numOfPeople) {
    • // Implement the urinal problem, described as "given x number of people walking
    • // into a bathroom that contains y number of urinals, describe the optimate
    • // placement of people so that none is standing next to the other"
    • // In this case, the urinals are represented by a boolean array with
    • // true representing a person at a urinal, and false meaning the urinal is empty
    • public static boolean[] populateBathroom(boolean[] urinals, int numOfPeople) {
    • //Implement the urinal problem, described as "given x number of people walking
    • //into a bathroom that contains y number of urinals, describe the optimate
    • //placement of people so that none is standing next to the other"
    • //In this case, the urinals are represented by a boolean array with
    • //true representing a person at a urinal, and false meaning the urinal is empty
    • int y = 0
    • if ( y == 3 ) {
    • idk how to solve this
    • }
    • return new boolean[] {true, false, true};
    • }
    • }

Pointers at the beginning and end of our index list (i = 0, j = end of index)
While i is less than j
if there is a mismatch return false !=
if not add i and take away -1 from j until i is equal to or larger than j

Code
Diff
  • public class Kata  {
      public static boolean detectPalindrome(String userWord){
     
            int i = 0, j = userWord.length() - 1;
     
            while (i < j) {
     
                if (userWord.charAt(i) != userWord.charAt(j))
                    return false;
              
                i++;
                j--;
            }
            return true;
        }
      }
    • public class Kata {
    • public static boolean detectPalindrome(String userWord) {
    • // Detect whether this string is a palindrome
    • return true;
    • }
    • }
    • public class Kata {
    • public static boolean detectPalindrome(String userWord){
    • int i = 0, j = userWord.length() - 1;
    • while (i < j) {
    • if (userWord.charAt(i) != userWord.charAt(j))
    • return false;
    • i++;
    • j--;
    • }
    • return true;
    • }
    • }
Code
Diff
  • public class Kata {
        public static int findIndex (int[] my_array, int t) {
           for(int i=0; i< my_array.length; i++){
                 if(my_array[i]==t){
                   return i;
                 }
             
             }
          return 4;
        }
      
    }
    • public class Kata {
    • public static int findIndex (int[] my_array, int t) {
    • // Find the index of t
    • return 4;
    • for(int i=0; i< my_array.length; i++){
    • if(my_array[i]==t){
    • return i;
    • }
    • }
    • return 4;
    • }
    • }