Ad

No Linq Solution

A solution for Adding the digits of an integer without the use of cringe ass linq.

Code
Diff
  • namespace Kumite
    {
        public class Problem
        {
            public static int SumDigitsOf(long integer)
            {
                int sum = 0;
                string numChars = integer.ToString();
    
                foreach (char numChar in numChars)
                {
                    if (char.IsDigit(numChar))
                    {
                        int num = int.Parse(numChar.ToString());
                        sum += num;
                    }
                }
    
                return sum;
            }
        }
    }
    • using System;
    • using System.Linq;
    • namespace Kumite
    • {
    • public class Problem
    • {
    • public static int SumDigitsOf(long integer)
    • {
    • return Math.Abs(integer).ToString().Sum(digit => digit - '0');
    • int sum = 0;
    • string numChars = integer.ToString();
    • foreach (char numChar in numChars)
    • {
    • if (char.IsDigit(numChar))
    • {
    • int num = int.Parse(numChar.ToString());
    • sum += num;
    • }
    • }
    • return sum;
    • }
    • }
    • }
Code
Diff
  • public class FizzBuzz
    {
        public string GetOutput(int number)
        {  
            if (number % 3 == 0 && number % 5 == 0)
            {
               return "FizzBuzz";
            }
            if (number % 3 == 0)  
            {  
                return "Fizz";  
            }  
            if (number % 5 == 0)  
            {  
                return "Buzz";  
            }
            return number.ToString();
        }
    }
    • public class FizzBuzz
    • {
    • public string GetOutput(int number) {
    • string str = "";
    • public string GetOutput(int number)
    • {
    • if (number % 3 == 0 && number % 5 == 0)
    • {
    • return "FizzBuzz";
    • }
    • {
    • return "FizzBuzz";
    • }
    • if (number % 3 == 0)
    • {
    • return "Fizz";
    • }
    • if (number % 5 == 0)
    • {
    • return "Buzz";
    • }
    • if (str.Length == 0)
    • {
    • str = number.ToString();
    • }
    • return str;
    • }
    • return number.ToString();
    • }
    • }
Code
Diff
  • public class FizzBuzz
    {
        public string GetOutput(int number)
        {
            string str = "";  
            if (number % 3 == 0)  
            {  
                str += "Fizz";  
            }  
            if (number % 5 == 0)  
            {  
                str += "Buzz";  
            }
            if (str == "")
            {
                str = number.ToString();
            }
    
            return str;
        }
    }
    • public class FizzBuzz
    • {
    • public string GetOutput(int number) {
    • for (int i = 1; i <= 100; i++)
    • {
    • public string GetOutput(int number)
    • {
    • string str = "";
    • if (i % 3 == 0)
    • if (number % 3 == 0)
    • {
    • str += "Fizz";
    • }
    • if (i % 5 == 0)
    • if (number % 5 == 0)
    • {
    • str += "Buzz";
    • }
    • if (str.Length == 0)
    • {
    • str = i.ToString();
    • }
    • Console.WriteLine(str);
    • }
    • return "0";
    • }
    • if (str == "")
    • {
    • str = number.ToString();
    • }
    • return str;
    • }
    • }