Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
factorial ncr + unique list
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here int t0,t1,t2,t3; List<int> num = new List<int>(new int[10]{1,2,3,4,5,6,7,8,9,10}); List<int> sub1 = num.GetRange(0,4); foreach (var obj in sub1) { Console.Write(obj+" "); } //Console.WriteLine(nCr(12,8)); //Console.WriteLine(Unique(num)); } public static bool Unique(List<int> t){ int count = 0; for (int i=0; i<t.Count()-1; i++){ for (int j=i+1; j<t.Count(); j++) { //Console.WriteLine(i + " " + j); if (!t[i].Equals(t[j])){ count++; } } } if (count.Equals(nCr(t.Count(),2))) { return true; } else return false; } public static int nCr(int n, int r) { return (Factorial(n)/Factorial(r))/Factorial(n-r); } public static int Factorial(int n) { if (n>0) { for (int i=n-1; i>1; i--) { n = n*i; } return n; } else if (n<0) throw new ArgumentOutOfRangeException("n","n should be non-zero"); else return 1; } } }
run
|
edit
|
history
|
help
0
aa
Dynamic
test linq select
p1
http://codegolf.stackexchange.com/questions/82526/sum-it-up-with-a-digital-triangle C# solution
NationalCode
Problem 5 SingleDigit
BEISPEIL- AUGUST 6 -2019
Pet Name Generator
"Live cooperation" problem fixed