Example #1
1
        void IDumpableAsText.DumpAsText(TextWriter writer)
        {
            var pbag = new List<KeyValuePair<String, String>>();
            Func<KeyValuePair<String, String>, String> fmt = kvp =>
            {
                var maxKey = pbag.Max(kvp1 => kvp1.Key.Length);
                return String.Format("    {0} : {1}", kvp.Key.PadRight(maxKey), kvp.Value);
            };

            Action<String> fillPbag = s =>
            {
                foreach (var line in s.SplitLines().Skip(1).SkipLast(1))
                {
                    var m = Regex.Match(line, "^(?<key>.*?):(?<value>.*)$");
                    var key = m.Result("${key}").Trim();
                    var value = m.Result("${value}").Trim();
                    pbag.Add(new KeyValuePair<String, String>(key, value));
                }
            };

            writer.WriteLine("Device #{0} \"{1}\" (/pci:{2}/dev:{3})", Index, Name, PciBusId, PciDeviceId);
            fillPbag(Simd.ToString());
            fillPbag(Clock.ToString());
            fillPbag(Memory.ToString());
            fillPbag(Caps.ToString());
            pbag.ForEach(kvp => writer.WriteLine(fmt(kvp)));
        }
Example #2
0
        static void Main(string[] args)
        {
            var players = new List<Player>();
            var shaker = new DiceShaker();

            for (var i = 0; i < 100; i++)
            {
                var player = Factory.CreatePlayer(shaker);
                System.Console.WriteLine(string.Format("Player {0}:\r\nThrowing Power: {1}\r\nTAS: {2}:\r\nTAM: {3}",
                    i,
                    player.ThrowPower.GetValue<double>(),
                    player.ThrowAccuracyShort.GetValue<double>(),
                    player.ThrowAccuracyMid.GetValue<double>()));
                players.Add(player);
            }

            var maxPotential = players.Select(w => w.GetPotential()).Max();
            var bestPlayer = players.First(w => w.GetPotential() == maxPotential);

            var maxMidAcc = players.Max(w => w.ThrowAccuracyMid.GetValue<double>());

            bestPlayer = players.First(w => w.ThrowAccuracyMid.GetValue<double>() == maxMidAcc);

            var maxShortAcc = players.Max(w => w.ThrowAccuracyShort.GetValue<double>());

            bestPlayer = players.First(w => w.ThrowAccuracyShort.GetValue<double>() == maxShortAcc);

            if (bestPlayer != null)
            {

            }
        }
Example #3
0
    private void ShowSampleItems_Click(object sender, EventArgs e) {
      // create some sample items;

      MyMap.MapElements.Clear();
      MyMap.Layers.Clear();

      var bounds = new List<LocationRectangle>();
      foreach (var area in DataManager.SampleAreas) {
        var shape = new MapPolygon();
        foreach (var parts in area.Split(' ').Select(cord => cord.Split(','))) {
          shape.Path.Add(new GeoCoordinate(double.Parse(parts[1], ci), double.Parse(parts[0], ci)));
        }

        shape.StrokeThickness = 3;
        shape.StrokeColor = Colors.Blue;
        shape.FillColor = Color.FromArgb((byte)0x20, shape.StrokeColor.R, shape.StrokeColor.G, shape.StrokeColor.B);
        bounds.Add(LocationRectangle.CreateBoundingRectangle(shape.Path));
        MyMap.MapElements.Add(shape);
      }

      var rect = new LocationRectangle(bounds.Max(b => b.North), bounds.Min(b => b.West), bounds.Min(b => b.South), bounds.Max(b => b.East));
      MyMap.SetView(rect);

      // show all Items
      var itemsLayer = new MapLayer();
      foreach (var item in DataManager.SampleItems) {
        DrawItem(item, "Ulm", itemsLayer);
      }

      MyMap.Layers.Add(itemsLayer);
    }
Example #4
0
    static void Main()
    {
        string input = Console.ReadLine();

        List<decimal> inputNums = new List<decimal>();
        List<decimal> oddNums = new List<decimal>();
        List<decimal> evenNums = new List<decimal>();

        string[] numbers = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

        foreach (var num in numbers)
        {
            inputNums.Add(decimal.Parse(num));
        }

        int index = 1;

        for (int i = 0; i < inputNums.Count; i++)
        {

            if (index % 2 == 1)
            {
                oddNums.Add(inputNums[i]);
            }
            else
            {
                evenNums.Add(inputNums[i]);
            }

            index++;
        }

        if (inputNums.Count == 0)
        {
            Console.WriteLine("OddSum=No, OddMin=No, OddMax=No, EvenSum=No, EvenMin=No, EvenMax=No");
        }

        else if (inputNums.Count == 1)
        {
            double oddNumsSum = (double)oddNums.Sum();
            double oddNumsMin = (double)oddNums.Min();
            double oddNumsMax = (double)oddNums.Max();
            
            Console.WriteLine("OddSum={0:G0}, OddMin={1:G0}, OddMax={2:G0}, EvenSum=No, EvenMin=No, EvenMax=No",
                oddNumsSum, oddNumsMin, oddNumsMax);
        }

        else
        {
            double oddNumsSum = (double)oddNums.Sum();
            double oddNumsMin = (double)oddNums.Min();
            double oddNumsMax = (double)oddNums.Max();
            double evenNumsSum = (double)evenNums.Sum();
            double evenNumsMin = (double)evenNums.Min();
            double evenNumsMax = (double)evenNums.Max();

            Console.WriteLine("OddSum={0:G0}, OddMin={1:G0}, OddMax={2:G0}, EvenSum={3:G0}, EvenMin={4:G0}, EvenMax={5:G0}",  // {...:G0} Remove trailing zeros
                oddNumsSum, oddNumsMin, oddNumsMax, evenNumsSum, evenNumsMin, evenNumsMax);
        }
    }
        //this method checks the rows
        private static string CheckHorizontals(string[,] theMatrix, int rows, int cols)
        {
            List<string> bestLine = new List<string>();

            for (int row = 0; row < rows; row++)
            {
                string nextLine = string.Empty;

                for (int col = 0; col < cols - 1; col++)
                {
                    if (col == 0)
                    {
                        nextLine += theMatrix[row, col] + ", ";
                    }

                    if (theMatrix[row, col + 1].Equals(theMatrix[row, col]))
                    {
                        nextLine += theMatrix[row, col + 1] + ", ";
                    }
                }

                bestLine.Add(nextLine);
            }

            if (bestLine.Count > 0)
            {
                return bestLine.Max().ToString().Substring(0, bestLine.Max().Length - 2);
            }
            else
            {
                return string.Empty;
            }
        }
Example #6
0
        public static Vector3 BestCircularFarmLocation(int radius, int range, int minMinions = 3)
        {
            var minions = EntityManager.MinionsAndMonsters.CombinedAttackable.Where(it => !it.IsDead && it.IsValidTarget(range));

            if (minions.Any() && minions.Count() == 1) return default(Vector3);

            var hitsperminion = new List<int>();
            int hits = new int();

            for (int i = 0; i < minions.Count(); i++)
            {
                hits = 1;

                for (int j = 0; j < minions.Count(); j++)
                {
                    if (j == i) continue;

                    if (minions.ElementAt(i).Distance(minions.ElementAt(j)) <= radius) hits++;
                }

                hitsperminion.Add(hits);
            }

            if (hitsperminion.Any() && hitsperminion.Max() > minMinions)
            {
                var pos = minions.ElementAt(hitsperminion.IndexOf(hitsperminion.Max())).ServerPosition;

                return pos;
            }

            return default(Vector3);
        }
Example #7
0
 private void DisplayWinner()
 {
     votes = new List<int>();
     votes.Add(toyStoryCount);
     votes.Add(starWarsCount);
     votes.Add(avengersCount);
     votes.Add(northCount);
     Console.WriteLine("");
     if (toyStoryCount == votes.Max())
     {
         Console.WriteLine("Toy Story wins with {0} votes", toyStoryCount);
     }
     else if (starWarsCount == votes.Max())
     {
         Console.WriteLine("Star Wars wins with {0} votes", starWarsCount);
     }
     else if (avengersCount == votes.Max())
     {
         Console.WriteLine("Avengers: Age of Ultron wins with {0} votes", avengersCount);
     }
     else if (northCount == votes.Max())
     {
         Console.WriteLine("North by Northwest wins with {0} votes", northCount);
     }
     else
     {
         Console.WriteLine("It's a tie");
     }
 }
Example #8
0
        internal static void Process()
        {
            Console.WriteLine("Day 2");
              int totPaper = 0;
              int totRibbon = 0;

              for (int i = 0; i < Day02.Input.Count; i++)
              {
            var inpLine = Day02.Input[i];
            int len = int.Parse(inpLine.Split('x')[0]);
            int width = int.Parse(inpLine.Split('x')[1]);
            int height = int.Parse(inpLine.Split('x')[2]);

            var lst = new List<int> { len, width, height };
            var smallest = lst.FindAll(d => d < lst.Max());

            if (smallest.Count == 1)
              smallest.Add(lst.Max());
            else if (smallest.Count == 0)
            {
              smallest.Add(lst.Max());
              smallest.Add(lst.Max());
            }

            totPaper += (2 * len * width) + (2 * width * height) + (2 * height * len) + ((int)smallest[0] * (int)smallest[1]);
            totRibbon += (2 * smallest[0]) + (2 * smallest[1]) + (len * width * height);
              }

              Console.WriteLine("  The elves should order " + totPaper + " sqft of wrapping-paper, and " + totRibbon + " feet of ribbon...");
        }
Example #9
0
        static void Main(string[] args)
        {
            int[] arr = new int[5];                                                 // array to keep numbers from user
            List<int> lista = new List<int>();                                      // list to keep all odd numbers from users numbers

            Console.WriteLine("Values for the array:");

            for (int i = 0; i < arr.Length; i++)                                    // loop taking numbers from user
            {
                Console.Write("Value for index {0}:", i);
                arr[i] = int.Parse(Console.ReadLine());
            }

            foreach (int x in arr)                                                  // loop adding all odd numbers(taken from arr[])
            {                                                                       // to lista (doasn't working on page if not x!=1)
                if (x % 2 != 0 & x != 1)
                    lista.Add(x);
            }

            for (int i = 0; i < arr.Length; i++)                                    // if we meet zero in lista, loop is looking for a max odd number from lista
            {                                                                       // and replace zero this number, next remove this number from lista
                if (arr[i] == 0 & lista.Count > 0)
                {
                    arr[i] = lista.Max();
                    lista.Remove(lista.Max());
                }
            }

            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine(arr[i]);
            }
        }
Example #10
0
 private static TableLayoutPanel GetLayoutPanel(List<List<Control>> controls)
 {
     int columnCount = controls.Max(list => list.Count);
     var layoutPanel = new TableLayoutPanel
                                {
                                    ColumnCount = columnCount,
                                    RowCount = controls.Count,
                                    Dock = DockStyle.Fill,
                                    Location = new Point(0, 0),
                                    Name = "layoutPanel",
                                    BorderStyle =  BorderStyle.Fixed3D
                                };
     int horizontalMargin = layoutPanel.Margin.Horizontal;
     for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
     {
         int controlIndex = columnIndex;
         bool columnExists = controls.Count - 1 >= columnIndex;
         try
         {
             int columnWidth = !columnExists ? 0 : controls.Max(control => control.Count <= controlIndex || control[controlIndex] == null
                                                                             ? 0 : control[controlIndex].Width 
                                                                                   + control[controlIndex].Margin.Horizontal) 
                                                                                   + horizontalMargin;
             layoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, columnWidth));
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
         }
     }
     return layoutPanel;
 }
Example #11
0
    static void Main()
    {
        var numbers = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

        var odd = numbers.WhereNot(x => x % 2 == 0);
        Console.WriteLine(string.Join(" ", odd));

        var numbersBiggerThanTen = numbers.WhereNot(LessThanTen);
        Console.WriteLine(string.Join(" ", numbersBiggerThanTen));
        Console.WriteLine();

        var students = new List<Student>()
        {
            new Student("Stavri",5.5),
            new Student("Loshiq",2),
            new Student("Me4a", 3.50),
            new Student("Anatoli", 4.4),
            new Student("Rambo", 5.95)
        };

        Console.WriteLine(students.Max(student => student.Grade));
        Console.WriteLine(students.Min(Grade));

        Console.WriteLine();
        Console.WriteLine(students.Max(Name));
        Console.WriteLine(students.Min(student => student.Name));
    }
Example #12
0
 private static Map ParseMap(string zone, string[] lines) {
     Map tmpMap = new Map();
     tmpMap.zone = zone;
     if (tmpMap.zone != "") {
         List<MapLineSegment> segmentList = new List<MapLineSegment>();
         foreach (string l in lines) {
             if (l[0] == 'L') {
                 segmentList.Add(ParseSegment(l));
             }
             else if (l[0] == 'P') {
                 //parse place
             }
         }
         //group up line segments according to color(RGB) value, then create one pen for each color used
         //this should greatly lower the overhead for creating brush and pen objects 
         //*edit* aparently not.
         List<MapLineSegment> distinctSegments = segmentList.Distinct(new MapLineSegmentColorComparer()).ToList();
         foreach (MapLineSegment colorSource in distinctSegments) {
             List<MapLineSegment> tmpSegmentList = segmentList.FindAll(x => x.color == colorSource.color);
             SolidColorBrush colorBrush = new SolidColorBrush(colorSource.color);
             Pen tmpPen = new Pen(colorBrush, 1.0);
             tmpMap.lineList.Add(new MapLine(tmpSegmentList, tmpPen));
         }
         if (segmentList.Count > 0) {
             tmpMap.maxX = Math.Max(segmentList.Max(x => x.aX), segmentList.Max(x => x.bX));
             tmpMap.maxY = Math.Max(segmentList.Max(x => x.aY), segmentList.Max(x => x.bY));
             tmpMap.minX = Math.Min(segmentList.Min(x => x.aX), segmentList.Min(x => x.bX));
             tmpMap.minY = Math.Min(segmentList.Min(x => x.aY), segmentList.Min(x => x.bY));
             tmpMap.width = tmpMap.maxX - tmpMap.minX;
             tmpMap.height = tmpMap.maxY - tmpMap.minY;
             tmpMap.depth = tmpMap.maxZ - tmpMap.minZ;
         }
     }
     return tmpMap;
 }
 private static int[] ExtractOfMaxNumbers(List<int> list, int k)
 {
     List<int> maxNumbers = new List<int>();
     for (int i = 0; i < k; i++)
     {
         maxNumbers.Add(list.Max());
         list.Remove(list.Max());
     }
     return maxNumbers.ToArray();
 }
        private void AddPlotSeries(List<Tuple<double, double>> ansv, double stepX, double stepY)
        {
            _stepX = stepX;
            _stepY = stepY;
            if (!_firstLoaded)
                DrawGrid(ansv.Min(item => item.Item1), ansv.Max(item => item.Item1), stepX,
                    ansv.Min(item => item.Item2), ansv.Max(item => item.Item2), stepY);

            MyCanvas.Children.Add(GenerateSeriesPath(ansv));
        }
    static void Main()
    {
        string numbersString = Console.ReadLine();
        if (numbersString == "")
        {
            Console.WriteLine("OddSum=No, OddMin=No, OddMax=No, EvenSum=No, EvenMin=No, EvenMax=No");
        }

        else
        {
            decimal[] numbers = Array.ConvertAll(numbersString.Split(' '), decimal.Parse);


            List<decimal> odd = new List<decimal>();
            List<decimal> even = new List<decimal>();


            for (int i = 0; i < numbers.Length; i++)
            {
                if (i % 2 == 0)
                {
                    odd.Add(numbers[i]);

                }
                else
                {
                    even.Add(numbers[i]);
                }
            }
            if ((odd.Count == 0 && even.Count == 0) || numbersString == "")
            {
                Console.WriteLine("OddSum=No, OddMin=No, OddMax=No, EvenSum=No, EvenMin=No, EvenMax=No");
            }
            if (even.Count == 0)
            {
                decimal oddSum = odd.Sum();
                decimal oddMin = odd.Min();
                decimal oddMax = odd.Max();
                Console.WriteLine("OddSum={0:0.##}, OddMin={1:0.##}, OddMax={2:0.##}, EvenSum=No, EvenMin=No, EvenMax=No", oddSum, oddMin, oddMax);
            }
            else
            {
                decimal oddSum = odd.Sum();
                decimal oddMin = odd.Min();
                decimal oddMax = odd.Max();

                decimal evenSum = even.Sum();
                decimal evenMin = even.Min();
                decimal evenMax = even.Max();

                Console.WriteLine("OddSum={0:0.##}, OddMin={1:0.##}, OddMax={2:0.##}, EvenSum={3:0.##}, EvenMin={4:0.##}, EvenMax={5:0.##}"
                                            , oddSum, oddMin, oddMax, evenSum, evenMin, evenMax);
            }
        }    
    }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="table"></param>
        /// <param name="chart"></param>
        /// <param name="indexAxisX"></param>
        /// <param name="indexAxisY"></param>
        public void Plot(DataTable table, Chart chart, int indexAxisX, int indexAxisY)
        {
            if (HasNull(table))
            {
                MessageBox.Show(@"Iterate data first!");
            }
            else
            {
                try
                {
                    var xValue = new List<double>();
                    var yValue = new List<double>();

                    foreach (var series in chart.Series)
                    {
                        series.Points.Clear();
                    }

                    for (var i = 1; i < table.Columns.Count; i++)
                    {
                        xValue.Add(
                            Convert.ToDouble(table.Rows[indexAxisX][i].ToString()));
                        yValue.Add(
                            Convert.ToDouble(table.Rows[indexAxisY][i].ToString()));
                    }

                    if (Math.Abs(xValue.Min() - xValue.Max()) < 0.0000001 ||
                        Math.Abs(yValue.Min() - yValue.Max()) < 0.0000001)
                    {
                        MessageBox.Show(@"The selected data cannot be charted!");
                    }
                    else
                    {
                        chart.Series[0].Points.DataBindXY(xValue, yValue);
                        chart.Series[0].ChartType = SeriesChartType.FastLine;
                        chart.Series[0].Color = Color.Black;
                        chart.ChartAreas[0].AxisX.Maximum = xValue.Max();
                        chart.ChartAreas[0].AxisX.Minimum = xValue.Min();
                        chart.ChartAreas[0].AxisY.Maximum = yValue.Max();
                        chart.ChartAreas[0].AxisY.Minimum = yValue.Min();
                        chart.ChartAreas[0].AxisX.MajorGrid.Enabled = true;
                        chart.ChartAreas[0].AxisY.MajorGrid.Enabled = true;
                        chart.ChartAreas[0].AxisX.Title =
                            table.Rows[indexAxisX][0].ToString();
                        chart.ChartAreas[0].AxisY.Title =
                            table.Rows[indexAxisY][0].ToString();
                        chart.Series[0].IsVisibleInLegend = false;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(@"Chart error: " + ex.Message);
                }
            }
        }
Example #17
0
 public static Point MaxPoint( List<Point> points, Axis axis )
 {
     double max;
     if(axis == Axis.X)
     {
         max = points.Max(p => p.X);
         return points.FirstOrDefault(p => DoubleCompare(p.X, max));
     }
     max = points.Max(p => p.Y);
     return points.FirstOrDefault(p => DoubleCompare(p.Y, max));
 }
        public static IList<Player> CreatePlayerList(int goalkeepers, int defenders, int midfielders, int forwards, int startingId = 0)
        {
            var players = new List<Player>();

            players.AddRange(CreatePlayers(startingId, Position.Goalkeeper, goalkeepers));
            players.AddRange(CreatePlayers(players.Max(p => p.Id), Position.Defender, defenders));
            players.AddRange(CreatePlayers(players.Max(p => p.Id), Position.Midfielder, midfielders));
            players.AddRange(CreatePlayers(players.Max(p => p.Id), Position.Forward, forwards));

            return players;
        }
Example #19
0
		public VectorPath(List<VectorPathSegment> seg)
		{
			segments = seg;
			Length = segments.Sum(p => p.Length);

			float top = segments.Min(p => p.Boundings.Top);
			float bot = segments.Max(p => p.Boundings.Bottom);
			float lef = segments.Min(p => p.Boundings.Left);
			float rig = segments.Max(p => p.Boundings.Right);

			Boundings = new FRectangle(lef, top, rig-lef, bot-top);
		}
Example #20
0
        public Rectangle boundingRectangle(List<Point> points)
        {
            // Add checks here, if necessary, to make sure that points is not null,
            // and that it contains at least one (or perhaps two?) elements

            var minX = points.Min(p => p.X);
            var minY = points.Min(p => p.Y);
            var maxX = points.Max(p => p.X);
            var maxY = points.Max(p => p.Y);

            return new Rectangle(new Point(minX, minY), new Size(maxX - minX, maxY - minY));
        }
Example #21
0
    static int ReturnMaxAfterN(int N, params int[] arr)
    {
        //Make new array that contain all ints from "arr" after N
        List<int> arrSec = new List<int> { };
        for (int i = N, j = 0; i < arr.Length; i++, j++)
        {
            arrSec.Add(arr[i]);
        }
        int max = arrSec.Max();
        arrSec.Remove(arrSec.Max());

        return max;
    }
Example #22
0
        private List<int> GetYearsToQueryFor()
        {
            var latestSuperRugbyYear = Int32.Parse(ConfigurationManager.AppSettings["LatestSuperRugbyYear"]);
            var yearsToGet = new List<int>();
            yearsToGet.Add(2006);

            while (yearsToGet.Max() < latestSuperRugbyYear)
            {
                yearsToGet.Add(yearsToGet.Max() + 1);
            }

            return yearsToGet;
        }
Example #23
0
 public static void GetEnvelope(double lat, double lon, double dist, out double minLat, out double minLon, out double maxLat, out double maxLon)
 {
     var gc = new GeodeticCalculator();
     var endpoints = new List<GlobalCoordinates>();
     endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(0), dist * 1000.0));
     endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(90), dist * 1000.0));
     endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(180), dist * 1000.0));
     endpoints.Add(gc.CalculateEndingGlobalCoordinates(Ellipsoid.WGS84, new GlobalCoordinates(new Angle(lat), new Angle(lon)), new Angle(270), dist * 1000.0));
     minLat = endpoints.Min(x => x.Latitude.Degrees);
     maxLat = endpoints.Max(x => x.Latitude.Degrees);
     minLon = endpoints.Min(x => x.Longitude.Degrees);
     maxLon = endpoints.Max(x => x.Longitude.Degrees);
 }
        public static DataClasses.CustomProgram GetCustomProgramRemotePB(int UserID)
        {
            DataClasses.GrucoxDataClassesRemoteDBDataContext dc = new DataClasses.GrucoxDataClassesRemoteDBDataContext();
            DataClasses.CustomProgram customProgramPB = new DataClasses.CustomProgram();
            List<DataClasses.GrucoxCustomProgramSession> ListcustomProgramPB = new List<DataClasses.GrucoxCustomProgramSession>();

            try
            {
                ListcustomProgramPB = (from sessions in dc.GetTable<DataClasses.GrucoxCustomProgramSession>()
                                       where sessions.LiveUserID == UserID
                                       select sessions).ToList<DataClasses.GrucoxCustomProgramSession>();
            }
            catch (Exception)
            {
                //For Diagnostics - Should be removed
                DataComms.CreateThreadInstance("DB Access during GetCustomProgramRemotePB");
            }
            finally
            {
                customProgramPB.LeftAvgConcP = ListcustomProgramPB.Max(z => z.LeftAvgConcP).HasValue ? (double)ListcustomProgramPB.Max(z => z.LeftAvgConcP) : 0.0;
                customProgramPB.LeftAvgEcceP = ListcustomProgramPB.Max(z => z.LeftAvgEcceP).HasValue ? (double)ListcustomProgramPB.Max(z => z.LeftAvgEcceP) : 0.0;
                customProgramPB.RightAvgConcP = ListcustomProgramPB.Max(z => z.RightAvgConcP).HasValue ? (double)ListcustomProgramPB.Max(z => z.RightAvgConcP) : 0.0;
                customProgramPB.RightAvgEcceP = ListcustomProgramPB.Max(z => z.RightAvgEcceP).HasValue ? (double)ListcustomProgramPB.Max(z => z.RightAvgEcceP) : 0.0;
            }
            return customProgramPB;
        }
Example #25
0
        public void Test()
        {
            Func<Entity, int> query = e => e.Count;

            var mockData = new List<Entity>
                {
                    new Entity() {Age = 20,Count = 1},
                    new Entity() {Age = 40,Count = 1},
                    new Entity() {Age = 60,Count = 1},
                };

            int a = mockData.Max(e => e.Count);
            int b = mockData.Max(query);
        }
Example #26
0
		public System.Drawing.Bitmap DrawBitmap(List<MazeImagePoint> labiryntImagePointCollection, int step)
		{
			int width = labiryntImagePointCollection.Max(obj => obj.X + 1) * step;
			int height = labiryntImagePointCollection.Max(obj => obj.Y + 1) * step;
			System.Drawing.Bitmap maze = new System.Drawing.Bitmap(width, height);
			int startX = 0;
			int endX = width - 1;
			int startY = 0;
			int endY = height - 1;

			using (var editor = System.Drawing.Graphics.FromImage(maze))
			{
				editor.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Black, 1), startX, startY, endX, endY);
			}

			foreach (MazeImagePoint labiryntImagePoint in labiryntImagePointCollection)
			{
				if (labiryntImagePoint.Operation == Operation.Nothing)
				{
					continue;
				}
				if (labiryntImagePoint.Operation == Operation.Right
					|| labiryntImagePoint.Operation == Operation.RightDown)
				{
					startX = labiryntImagePoint.X * step;
					endX = (labiryntImagePoint.X + 1) * step;
					startY = labiryntImagePoint.Y * step;
					endY = labiryntImagePoint.Y * step;
					using (var editor = System.Drawing.Graphics.FromImage(maze))
					{
						editor.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Black, 3), startX, startY, endX, endY);
					}
				}
				if (labiryntImagePoint.Operation == Operation.Down
					|| labiryntImagePoint.Operation == Operation.RightDown)
				{
					startX = labiryntImagePoint.X * step;
					endX = labiryntImagePoint.X * step;
					startY = labiryntImagePoint.Y * step;
					endY = (labiryntImagePoint.Y + 1) * step;
					using (var editor = System.Drawing.Graphics.FromImage(maze))
					{
						editor.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Black, 3), startX, startY, endX, endY);
					}
				}
			}
			return maze;
		}
 static void Main()
 {
     Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
     float[] allNumbers = Console.ReadLine().Split(' ').Select(float.Parse).ToArray();
     List<float> fpNumbers = new List<float> { };
     List<int> integerNumbers = new List<int> { };
     for (int index = 0; index < allNumbers.Length; index++)
     {
         if (allNumbers[index].ToString().Contains('.'))
         {
             fpNumbers.Add(allNumbers[index]);
         }
         else
         {
             integerNumbers.Add((int)allNumbers[index]);
         }
     }
     Console.WriteLine("[{0}] -> min: {1}, max: {2}, sum: {3}, avg: {4:f2}"
         , string.Join(", ", fpNumbers)
         , fpNumbers.Min()
         , fpNumbers.Max()
         , fpNumbers.Sum()
         , fpNumbers.Average());
     Console.WriteLine("[{0}] -> min: {1}, max: {2}, sum: {3}, avg: {4:f2}"
         , string.Join(", ", integerNumbers)
         , integerNumbers.Min()
         , integerNumbers.Max()
         , integerNumbers.Sum()
         , integerNumbers.Average());
 }
Example #28
0
        /*
         Write a program that finds the most frequent number in an array. Example:
	        {4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3}  4 (5 times)
         */
        static void Main(string[] args)
        {
            int[] sequence = { 4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3 };

            List<int> sequenceWithNoRepeatings = new List<int>();
            List<int> occurences = new List<int>();

            int indexToAddAt = 0;
            for (int i = 0; i < sequence.Length; i++)
            {
                indexToAddAt = 0;

                if (!sequenceWithNoRepeatings.Contains(sequence[i]))
                {
                    sequenceWithNoRepeatings.Add(sequence[i]);
                    occurences.Add(1);
                }
                else
                {
                    indexToAddAt = sequenceWithNoRepeatings.IndexOf(sequence[i]);
                    occurences[indexToAddAt]++;
                }
            }

            int maxOccurence = occurences.Max();
            int postion = occurences.IndexOf(maxOccurence);

            Console.WriteLine("Sequence: " + String.Join(",", sequence));
            Console.WriteLine(sequenceWithNoRepeatings[postion] + " -> " + occurences[postion] + " times");
        }
Example #29
0
        static void Main(string[] args)
        {
            string[] numbers = Console.ReadLine().Split(' ');
            List<double> floatingNumbers = new List<double>();
            List<int> integerNumbers = new List<int>();
            foreach(string number in numbers)
            {
                if (number.Contains("."))
                {
                    double number2 = double.Parse(number);

                    if (number2 % 1 == 0)
                    {
                        integerNumbers.Add(Convert.ToInt32(number2));
                    }
                    else
                    {
                        floatingNumbers.Add(number2);
                    }
                }
                else
                {
                    integerNumbers.Add(int.Parse(number));
                }
            }
            string output = string.Join(", ", floatingNumbers);
            Console.WriteLine("{0} -> min: {1:f2}, max: {2:f2}, sum: {3:f2}, avg: {4:f2}", output, floatingNumbers.Min(), floatingNumbers.Max(),
                floatingNumbers.Sum(), floatingNumbers.Average());
            output = string.Join(", ", integerNumbers);
            Console.WriteLine("{0} -> min: {1}, max: {2}, sum: {3}, avg: {4:f2}", output, integerNumbers.Min(), integerNumbers.Max(),
                integerNumbers.Sum(), integerNumbers.Average());
        }
        public ActionResult Index(int id, List<int> grSel) {
            var db = new ZkDataContext();
            var post = db.ForumPosts.Find(id);

            string txt1;
            string txt2;

            if (grSel != null && grSel.Any())
            {
                if (grSel.Count > 1)
                {
                    txt1 = db.ForumPostEdits.Find(grSel.Min()).NewText;
                    txt2 = db.ForumPostEdits.Find(grSel.Max()).NewText;
                } else
                {
                    var edit = db.ForumPostEdits.Find(grSel.First());
                    txt1 = edit.OriginalText;
                    txt2 = edit.NewText;
                }

                var sd = new SideBySideDiffBuilder(new Differ());
                ViewBag.DiffModel = sd.BuildDiffModel(txt1, txt2);
            } else
            {
                var edit = post.ForumPostEdits.OrderByDescending(x => x.ForumPostEditID).FirstOrDefault();
                if (edit != null)
                {
                    var sd = new SideBySideDiffBuilder(new Differ());
                    ViewBag.DiffModel = sd.BuildDiffModel(edit.OriginalText, edit.NewText);
                }
            }


            return View("PostHistoryIndex", post);
        }