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);
- }
- }
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
Mathematics