C# : Shortest Solutions
Shortest Solutions In C#
using System.Linq; public class Program { public static int func_five(int start, int end) { return Enumerable.Range(start, end-start+1).Count(x => !x.ToString().Contains("5")); } }
using System.Linq; public class Program { public static int func_short(string s) { return s.Split(' ').Min(x => x.Length); } }
using static System.Math; public class Program { public static long func_square(long num) { return Sqrt(num) % 1 == 0 ? (long)Pow(Sqrt(num) + 1, 2) : -1; } }
using System; using System.Collections.Generic; using System.Linq; public class Program { public static Listfunc_RemoveSmallest(List numbers) { numbers.Remove(numbers.DefaultIfEmpty().Min()); return numbers; } }
using System; using System.Linq; using System.Text.RegularExpressions; public class Program { public static bool func_ValidatePin(string pin) { return pin.All(n => Char.IsDigit(n)) && (pin.Length == 4 || pin.Length == 6); } }
using System.Collections.Generic; using System.Linq; using System; public class Program { public static int funv_find(int[] integers) { return integers.Count(a=>a%2==1)>1?integers.Single(a=>a%2==0):integers.Single(a=>a%2==1); } }
using System; using System.Linq; public class Program { public static bool func_isogram(string str) { return str.ToLower().Distinct().Count()==str.Length; } }
using System; public static class Program { public static long func_SumOddNumbers(long n) => (long)Math.Pow(n, 3); }
using System; using System.Text.RegularExpressions; public static class Program { public static string func_disemvowel(string str) { return Regex.Replace(str, @"(?i)[aeiou]", ""); } }
using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System; public class Program { public static string func_reverse(string sentence) { return Regex.Replace(sentence, @"\b\S{5,}\b", (x) => string.Concat(x.Value.Reverse())); } }
using System.Linq; public class Program { public static bool func_Walk(string[] walk) { return walk.Count(x => x == "n") == walk.Count(x => x == "s") && walk.Count(x => x == "e") == walk.Count(x => x == "w") && walk.Length == 10; } }
using System; using System.Linq; using System.Text.RegularExpressions; public static class Program { public static int func_count(string word) => new Regex("[aeiouy]", RegexOptions.IgnoreCase).Matches(word).Cast().Count(); }
It convert given base to target base(binary,hexadecimal,decimal,octal,alpha and alpha_(lower,upper,numeric) types).
using System; using System.Linq; public class Program{ public string Convert(string input, string source_base, string target_base) { var a= input.Select((x,n)=>source_base.IndexOf(x)*(long)Math.Pow(source_base.Length,input.Length-1-n)).Sum(); string rs; for (rs="";a>0;a/=target_base.Length) rs=target_base[(int)(a%target_base.Length)]+rs; return input=="0" ? target_base[0]+"" : rs; } }
Comments