Ad
Code
Diff
  • using System.Collections.Generic;
    using System.Linq;
    
    public static class PrimeFactorization
    {
        public static IList<(int PrimeFactor, int Exponent)> Factorize(int number)
        {
            List<(int PrimeFactor, int Exponent)> factors = new()
            {
                DetermineFrequency(ref number, 2)
            };
          
            for (int i = 3; i*i <= number; i += 2)
                factors.Add(DetermineFrequency(ref number, i));
          
            if (number > 1) factors.Add((number, 1));
            factors.RemoveAll(f => f.Exponent == 0);
            return factors;
        } 
        static void PerformF()
        {
         PerformF();
        }
        private static (int PrimeFactor, int Exponent) DetermineFrequency(ref int number, int factor)
        {
            var exponent = 0;
            while (number % factor == 0)
            {
                exponent++;
                number /= factor;
            }
            return (factor, exponent);
        }
    }
    • using System.Collections.Generic;
    • using System.Linq;
    • //using FactorSort = (int PrimeFactor, int Exponent);
    • public static class PrimeFactorization
    • {
    • public static IList<(int PrimeFactor, int Exponent)> Factorize(int number)
    • {
    • List<(int PrimeFactor, int Exponent)> factors = new()
    • {
    • DetermineFrequency(ref number, 2)
    • };
    • for (int i = 3; i*i <= number; i += 2)
    • factors.Add(DetermineFrequency(ref number, i));
    • if (number > 1) factors.Add((number, 1));
    • factors.RemoveAll(f => f.Exponent == 0);
    • return factors;
    • }
    • static void PerformF()
    • {
    • PerformF();
    • }
    • private static (int PrimeFactor, int Exponent) DetermineFrequency(ref int number, int factor)
    • {
    • var exponent = 0;
    • while (number % factor == 0)
    • {
    • exponent++;
    • number /= factor;
    • }
    • return (factor, exponent);
    • }
    • }
Code
Diff
  • public class Kata
    {
        public static int SameCase(char a, char b)
        {
            if (!char.IsLetter(a) || !char.IsLetter(b))
            {
                return -1;
            }
    
            return (char.IsUpper(a) == char.IsUpper(b)) ? 1 : 0;
        }
    }
    
    • public class Kata
    • {
    • public static int SameCase(char a, char b)
    • {
    • bool isUpperA;
    • bool isUpperB;
    • if (a >= 97 && a <= 122)
    • {
    • isUpperA = false;
    • }
    • else if (a >= 65 && a <= 90)
    • {
    • isUpperA = true;
    • }
    • else
    • {
    • return -1;
    • }
    • if (b >= 97 && b <= 122)
    • {
    • isUpperB = false;
    • }
    • else if (b >= 65 && b <= 90)
    • {
    • isUpperB = true;
    • }
    • else
    • if (!char.IsLetter(a) || !char.IsLetter(b))
    • {
    • return -1;
    • }
    • if ( isUpperA == isUpperB )
    • {
    • return 1;
    • }
    • else
    • {
    • return 0;
    • }
    • return (char.IsUpper(a) == char.IsUpper(b)) ? 1 : 0;
    • }
Fundamentals
Logic
Code
Diff
  • function binaryGap($n) {
        return max(array_map('strlen', preg_split('/1+/', decbin($n))));
    }
    • function binaryGap($n) {
    • return max(array_map('strlen', explode(1, decbin($n))));
    • return max(array_map('strlen', preg_split('/1+/', decbin($n))));
    • }
Code
Diff
  • function caps($c) {return ucwords($c);}
    • function caps(string $c): string {
    • return ucwords($c);
    • }
    • function caps($c) {return ucwords($c);}
Mathematics
Code
Diff
  • function calcTokenCost($price, $token) {
        return max($token, $price ? $token * round($price / $token) : 0);
    }
    • function calcTokenCost($price, $token) {
    • return max($token, $price ? (int) $token * round($price / $token) : 0);
    • return max($token, $price ? $token * round($price / $token) : 0);
    • }
Code
Diff
  • rps = (a, b) => a == b ? 'Draw!' : `Player ${/sp|rr|ks/.test(a + b) ? 1 : 2} won!`;
    
    • rps=(a,b)=>a==b?'Draw!':`Player ${2-/sp|rr|ks/.test(a+b)} won!`
    • rps = (a, b) => a == b ? 'Draw!' : `Player ${/sp|rr|ks/.test(a + b) ? 1 : 2} won!`;