Ad
Code
Diff
  • using System;
    using System.Linq;
    using System.Linq.Expressions;
    
    public class ArtihmeticParser
    {
      public static int EvaluateSum(string input)
      {
        // [1,3,4,6] --> 0+1 = 1, 1+3 = 4, 4+4 = 8, 8+6 = 14
        return input.Split("+").Select(EvaluateProduct).Aggregate(0,(a,b) => a+b);
      }
      
      private static int EvaluateProduct(string input)
      {
        // [1,3,4,6] --> 1*1 = 1, 1*3 = 3, 3*4 = 12, 12*6 = 72 
        return input.Split("*").Select(EvaluateInteger).Aggregate(1,(a,b) => a*b);
      }
      
      private static int EvaluateInteger(string input)
      {
        return int.Parse(input);
      }
      
      private static int EvaluateDifference(string input)
      {
        /* Expression subtractExpr = Expression.Subtract {
        Expression.Constant(a),
        Expression.Constant(b)
        };
        Console.WriteLine(Expression.Lambda<Func<int>>(subtractExpr).Compile().Invoke());
        */
        
         //return input.Split("-").Select(EvaluateSum).Aggregate(0,(a,b) => a-b);
             // int numOfValues;
             // int numOfValues = 0;
         input.Split("-");
         int a = input[0];
         int b = input[1];
            //  int answer = a - b;
        // for(int i = 0; i < input.Length; i++) {
        //    int result = a - b;
           // return result;
           // do I need a while loop? while i > 1
            }
        // return result;
        }
      }
    • using System;
    • using System.Linq;
    • using System.Linq.Expressions;
    • public class ArtihmeticParser
    • {
    • public static int Evaluate(string input)
    • public static int EvaluateSum(string input)
    • {
    • // [1,3,4,6] --> 0+1 = 1, 1+3 = 4, 4+4 = 8, 8+6 = 14
    • return input.Split("+").Select(EvaluateProduct).Aggregate(0,(a,b) => a+b);
    • }
    • private static int EvaluateProduct(string input)
    • {
    • // [1,3,4,6] --> 1*1 = 1, 1*3 = 3, 3*4 = 12, 12*6 = 72
    • return input.Split("*").Select(EvaluateInteger).Aggregate(1,(a,b) => a*b);
    • }
    • private static int EvaluateInteger(string input)
    • {
    • return int.Parse(input);
    • }
    • }
    • private static int EvaluateDifference(string input)
    • {
    • /* Expression subtractExpr = Expression.Subtract {
    • Expression.Constant(a),
    • Expression.Constant(b)
    • };
    • Console.WriteLine(Expression.Lambda<Func<int>>(subtractExpr).Compile().Invoke());
    • */
    • //return input.Split("-").Select(EvaluateSum).Aggregate(0,(a,b) => a-b);
    • // int numOfValues;
    • // int numOfValues = 0;
    • input.Split("-");
    • int a = input[0];
    • int b = input[1];
    • // int answer = a - b;
    • // for(int i = 0; i < input.Length; i++) {
    • // int result = a - b;
    • // return result;
    • // do I need a while loop? while i > 1
    • }
    • // return result;
    • }
    • }
Code
Diff
  • public class Kata {
      public static boolean detectPalindrome(String userWord) {
        // Detect whether this string is a palindrome
        String backwardsWord = new StringBuilder(userWord).reverse().toString();
        if (!userWord.equals(backwardsWord)) {
          return false;
        }
        return true;
      }
    }
    • public class Kata {
    • public static boolean detectPalindrome(String userWord) {
    • // Detect whether this string is a palindrome
    • String backwardsWord = new StringBuilder(userWord).reverse().toString();
    • if (!userWord.equals(backwardsWord)) {
    • return false;
    • }
    • return true;
    • }
    • }
Code
Diff
  • public class Kata {
      public static boolean detectPalindrome(String userWord) {
        // Detect whether this string is a palindrome
        
    // turn userWord into array of characters
        // Create array that = string length
        char[] ch = new char[userWord.length()];
      
            // Copy character by character into array
            for (int i = 0; i < ch.length; i++) {
                ch[i] = userWord.charAt(i);
            }
        // reverse the string and convert it to char[] array
        char[] chBackwards = new StringBuilder(userWord).reverse().toString().toCharArray();
        
        // iterate through both indexes and see if (for ex.) index0 = index0
            for(int i = 0; i < ch.length; i++) {
                if(ch[i] != chBackwards[i]) {
                  return false;
                }
            }
        return true;
      }
    }
    
    
    // --------------------
    // make ch array for og word
    // make ch array for og word backwards
    // iterate through both array lists index
    // if all indexs are = to eachother
    // return true
    • public class Kata {
    • public static boolean detectPalindrome(String userWord) {
    • // Detect whether this string is a palindrome
    • // turn userWord into array of characters
    • // Create array that = string length
    • char[] ch = new char[userWord.length()];
    • // Copy character by character into array
    • for (int i = 0; i < ch.length; i++) {
    • ch[i] = userWord.charAt(i);
    • }
    • // reverse the string and convert it to char[] array
    • char[] chBackwards = new StringBuilder(userWord).reverse().toString().toCharArray();
    • // iterate through both indexes and see if (for ex.) index0 = index0
    • for(int i = 0; i < ch.length; i++) {
    • if(ch[i] != chBackwards[i]) {
    • return false;
    • }
    • }
    • return true;
    • }
    • }
    • }
    • // --------------------
    • // make ch array for og word
    • // make ch array for og word backwards
    • // iterate through both array lists index
    • // if all indexs are = to eachother
    • // return true