Ad
Code
Diff
  • using System;
    using System.Linq;
    using System.Collections.Generic;
    
    namespace Kumite
    {
      public class Problem
      {
        public static int SumDigitsOf(long integer) => 
          Array.ConvertAll(integer.ToString().TrimStart('-').ToCharArray(), 
            c => (int)Char.GetNumericValue(c)).Sum();
      }
    }
    • using System;
    • using System.Linq;
    • using System.Collections.Generic;
    • namespace Kumite
    • {
    • public class Problem
    • {
    • public static int SumDigitsOf(long integer) => (int)(from ch in integer.ToString()
    • where Char.IsDigit(ch)
    • select Char.GetNumericValue(ch)).Sum();
    • public static int SumDigitsOf(long integer) =>
    • Array.ConvertAll(integer.ToString().TrimStart('-').ToCharArray(),
    • c => (int)Char.GetNumericValue(c)).Sum();
    • }
    • }
Code
Diff
  • using System;
    using System.Linq;
    using System.Collections.Generic;
    
    namespace Kumite
    {
      public class Problem
      {
        public static int SumDigitsOf(long integer)
        {
          return (int)(from ch in integer.ToString()  
              where Char.IsDigit(ch)  
              select Char.GetNumericValue(ch)).Sum();
        }
      }
    }
    • using System;
    • using System.Linq;
    • using System.Collections.Generic;
    • namespace Kumite
    • {
    • public class Problem
    • {
    • public static int SumDigitsOf(long integer)
    • {
    • return integer.GetDigits().Sum();
    • return (int)(from ch in integer.ToString()
    • where Char.IsDigit(ch)
    • select Char.GetNumericValue(ch)).Sum();
    • }
    • }
    • public static class LongExtensions
    • {
    • public static IEnumerable<int> GetDigits(this long number)
    • {
    • number = Math.Abs(number);
    • while (number > 9)
    • {
    • yield return (int)(number % 10);
    • number /= 10;
    • }
    • yield return (int)number;
    • }
    • }
    • }
Fundamentals
Code
Diff
  • using System;
    
    public class Kata
        {
            public  static int Opposite(int number) => number/-1;
        }
    • using System;
    • public class Kata
    • {
    • public static int Opposite(int number)
    • {
    • // Happy Coding
    • return number/-1;
    • }
    • public static int Opposite(int number) => number/-1;
    • }