Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace NullWeight
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, List<Tuple<string, int>>> dict = new Dictionary<string, List<Tuple<string, int>>>();
  14.             Random rnd = new Random();
  15.             List<Tuple<string, int>> testList = new List<Tuple<string, int>>();
  16.             for(int i = 0; i<6; i++) testList.Add(Tuple.Create<string, int>("*", rnd.Next(500)));
  17.             for (int i = 0; i < 4; i++) testList.Add(Tuple.Create<string, int>("*", 0));
  18.  
  19.             dict.Add("test",  testList);
  20.             foreach (Tuple<string, int> t in testList) Console.Write(t.Item2.ToString() + ",");
  21.             Console.WriteLine();
  22.  
  23.             foreach (KeyValuePair<string, List<Tuple<string, int>>> d in dict)
  24.             {
  25.                 int tWeight = 0; int nullCount = 0; int propValue = 0;
  26.                 foreach(Tuple<string, int> t in d.Value)
  27.                 {
  28.                     tWeight += t.Item2;
  29.                     if (t.Item2 == 0) nullCount++;
  30.                 }
  31.                 Console.WriteLine("origTotal: " + tWeight);
  32.                 propValue = (tWeight / d.Value.Count);
  33.                 float proptWeight = (float)tWeight * (1f+ (float)nullCount / (float)d.Value.Count);
  34.                 Console.WriteLine("propTotal: " + proptWeight);
  35.                 Console.WriteLine("Ratio: " + nullCount + "/" + d.Value.Count);
  36.                 Console.WriteLine("PropValue: " + propValue);
  37.                 Console.WriteLine("Orig+prop: " + (tWeight + propValue * nullCount));
  38.             }
  39.             Console.ReadLine();
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement