Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Codes_Maker;
- namespace ConsoleApplication1
- {
- class Program
- {
- static Func<int, int> factorial = new Func<int, int>((x) => x > 1 ? x * factorial(x - 1) : 1);
- static int numberOfCombinations = 0;
- static void SetOfCombinations(int n, int r, out string[] ArrayOfWords, ref int numberOfCombinations)
- {
- int[] x = new int[r + 2];
- int[] min = new int[r + 1];
- int[] max = new int[r + 1];
- int i = 0, j = 0, p = 0, d = 0;
- string s = "";
- ArrayOfWords = new string[numberOfCombinations];
- for (j = 1; j < r + 1; j++)
- {
- max[j] = n - j + 1;
- min[j] = r - j + 1;
- x[j] = min[j];
- }
- while (i <= r)
- {
- for (j = r; j > 0; j--) s = s + Convert.ToString(x[j]);
- ArrayOfWords[d] = s;
- p++; i = 1;
- while ((i <= r) && (x[i] == max[i])) i++;
- if (i <= r) x[i]++;
- for (j = i - 1; j >= 0; j--)
- {
- min[j] = x[j + 1] + 1;
- x[j] = min[j];
- }
- s = "";
- d++;
- }
- }
- static public void BuildCode(int n, int r, int p, string[] ArrayOfWords, out int[,] Matrix, out int[] Weights, ref int numberOfCombinations)
- {
- Matrix = new int[n - 1, numberOfCombinations];
- int f1 = 0, f2 = 0;
- Weights = new int[n - 1];
- for (int i = 1; i <= n - 1; i++)
- {
- for (int l = 0; l <= numberOfCombinations - 1; l++)
- {
- for (int j = 0; j <= r - 1; j++)
- {
- if (Convert.ToByte(ArrayOfWords[l][j] - 48) == i) f1 = 1;
- if (Convert.ToByte(ArrayOfWords[l][j] - 48) == i + 1) f2 = 1;
- }
- if (f1 == f2)
- {
- Matrix[i - 1, l] = 0; Console.Write(Matrix[i - 1, l]);
- }
- if (f1 > f2)
- {
- Matrix[i - 1, l] = 1; Console.Write(Matrix[i - 1, l]); Weights[i - 1]++;
- }
- if (f1 < f2)
- {
- Matrix[i - 1, l] = FiniteFieldsMath.Inverse(-1, p); Console.Write(Matrix[i - 1, l]); Weights[i - 1]++;
- }
- f1 = 0;
- f2 = 0;
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- int n = 0, r = 0, p = 0, q = 0;
- double sigma = 0, R = 0, Nn;
- Nn = n;
- n = Convert.ToInt32(Console.ReadLine());
- r = Convert.ToInt32(Console.ReadLine());
- p = Convert.ToInt32(Console.ReadLine());
- q = Convert.ToInt32(Console.ReadLine());
- numberOfCombinations = (factorial(n) / (factorial(n - r) * factorial(r)));
- int[,] Matrix = new int[n - 1, numberOfCombinations];
- int[] Weights = new int[n - 1];
- string[] ArrayOfWords = new string[numberOfCombinations];
- SetOfCombinations(n, r, out ArrayOfWords, ref numberOfCombinations);
- BuildCode(n, r, p, ArrayOfWords, out Matrix, out Weights, ref numberOfCombinations);
- double d = Weights.Min();
- sigma = d / (n - 1);
- R = Math.Log(numberOfCombinations, q) / n;
- Console.WriteLine("d(C) = {0}", d);
- Console.WriteLine("Sigma = {0}", sigma);
- Console.WriteLine("R = {0}", R);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement