### FizzBuzz

Fundamentals
Strings
Code
Diff
• ``````public class FizzBuzz
{
public string GetOutput(int number) =>
(number % 3, number % 5) switch
{
(0, 0) => "FizzBuzz",
(0, _) => "Fizz",
(_, 0) => "Buzz",
(_, _) => \$"{number}"
};
}``````
•  1 1 public class FizzBuzz 2 − { 3 − public string GetOutput(int number) 4 − { 5 − var ret = string.Empty; 6 − 7 − if (number % 3 == 0) 8 − ret += "Fizz"; 9 − if (number % 5 == 0) 10 − ret += "Buzz"; 11 − 12 − if (ret.Length == 0) 13 − ret = number.ToString(); 14 − return ret; 15 − } 2 + { 3 + public string GetOutput(int number) => 4 + (number % 3, number % 5) switch 5 + { 6 + (0, 0) => "FizzBuzz", 7 + (0, _) => "Fizz", 8 + (_, 0) => "Buzz", 9 + (_, _) => \$"{number}" 10 + }; 16 16 }

### Adding the digits of an integer

We can use recursion because the size of long is limited
Also we could combine two methods like this:

``````f(x) => x == 0 ? 0 : x < 0 ? f(-x) : x % 10 + f(x / 10);
``````

or even multiply by the signum of x on each iteration:

``````(x >> sizeof(long) * 8 - 1 << 1) + 1
``````

but it is a bit slower.

Code
Diff
• ``````using System;
using System.Linq;
using System.Collections.Generic;

namespace Kumite
{
public class Problem
{
public static long SignedSumDigitsOf(long x) =>
x == 0 ? 0 : x % 10 + SignedSumDigitsOf(x / 10);

public static long SumDigitsOf(long x) =>
SignedSumDigitsOf(x) * Math.Sign(x);
}
}``````
•  1 1 using System; 2 2 using System.Linq; 3 3 using System.Collections.Generic; 4 4 5 5 namespace Kumite 6 6 { 7 − public class Problem 8 − { 9 − public static int SumDigitsOf(long integer) => 10 − Array.ConvertAll(integer.ToString().TrimStart('-').ToCharArray(), 11 − c => (int)Char.GetNumericValue(c)).Sum(); 12 − } 7 + public class Problem 8 + { 9 + public static long SignedSumDigitsOf(long x) => 10 + x == 0 ? 0 : x % 10 + SignedSumDigitsOf(x / 10); 11 + 12 + public static long SumDigitsOf(long x) => 13 + SignedSumDigitsOf(x) * Math.Sign(x); 14 + } 13 13 }

### Is Isogram?

Code
Diff
• ``````using System.Linq;
using System.Collections.Generic;

public class Kata
{
public static bool IsIsogram(string str, HashSet<int> hs = null) =>
str.All(c => (hs ??= new HashSet<int>()).Add(c & 0x1f));
}``````
•  1 1 using System.Linq; 2 + using System.Collections.Generic; 2 2 3 3 public class Kata 4 4 { 5 − public static bool IsIsogram(string str) => str.Length == str.ToLower().Distinct().Count(); 6 + public static bool IsIsogram(string str, HashSet hs = null) => 7 + str.All(c => (hs ??= new HashSet()).Add(c & 0x1f)); 6 6 }