示例#1
0
        protected override void DoSilver()
        {
            PerfMon.Monitor("Parse", () => ParseInput());

            PerfMon.Monitor("Calculate", () =>
            {
                newSeatStatus = Seats;
                cycles        = 0;
                while (cycles == 0 || !StatusSame(Seats, newSeatStatus))
                {
                    cycles++;
                    Seats         = newSeatStatus;
                    newSeatStatus = Seats.Select(x => new char[x.Count()]).ToList();
                    for (int row = 0; row < Seats.Count; row++)
                    {
                        for (int seat = 0; seat < Seats[row].Count(); seat++)
                        {
                            Evaluate2(row, seat);
                        }
                    }
                }
                Console.WriteLine("Done in {0} cycles", cycles);
                Result = Seats.Sum(x => x.Count(y => y == '#'));
            });
        }
示例#2
0
        private Expression TMethodOrProperty(string id)
        {
            PerfMon.Start("MethodOrProperty");

            string objectId = null;

            if (M(TokenType.Dot))
            {
                Consume();

                objectId = id;
                id       = T();

                Consume(TokenType.Id);
            }


            Expression result;

            if (M(TokenType.LeftPar))
            {
                result = TMethod(objectId, id);
            }
            else
            {
                result = TProperty(objectId, id);
            }

            PerfMon.Stop("MethodOrProperty");

            return(result);
        }
示例#3
0
 protected override void DoGold()
 {
     PerfMon.Monitor("Calculate", () =>
     {
         Result = CountGold(bags.First(x => x.LuggageKind == "shiny gold"));
     });
 }
示例#4
0
        protected override void DoSilver()
        {
            PerfMon.Monitor("Parse", () =>
            {
                ParseInput();
            });


            PerfMon.Monitor("Calculate", () =>
            {
                var memory = new long[masks.SelectMany(x => x.ValueToMemoryPosition.Select(y => y.MemoryAddress)).Max()];

                foreach (var mask in masks)
                {
                    ApplyMask(mask, memory);
                }

                var result = (long)0;
                foreach (var val in memory)
                {
                    result += val;
                }

                Result = result;
            });
        }
示例#5
0
        protected override void DoGold()
        {
            PerfMon.Monitor("Calculate", () =>
            {
                Result = 0;
                Rules.First(x => x.Id == 8).Constraint  = "42 | 42 8";
                Rules.First(x => x.Id == 11).Constraint = "42 31 | 42 11 31";

                var allCombinations  = GetString(42);
                var allCombinations2 = GetString(31);

                foreach (var input in Inputs)
                {
                    for (int i = 1; i < 20; i++)
                    {
                        var ft = allCombinations.Aggregate((a, b) => a + "|" + b);
                        var to = allCombinations2.Aggregate((a, b) => a + "|" + b);
                        var a  = Regex.Match(input, $"^({ft})+(({ft})" + "{" + i + "}" + $"({to})" + "{" + i + "}" + ")$");
                        if (a.Success)
                        {
                            Result++;
                        }
                    }
                }
            });
        }
示例#6
0
        protected override void ParseInput()
        {
            PerfMon.Monitor("Read", () =>
            {
                var input             = ReadInput();
                StringBuilder builder = new StringBuilder();
                int count             = 0;
                for (int i = 0; i < input.Length; i++)
                {
                    if (string.IsNullOrEmpty(input[i]) || i == input.Length - 1)
                    {
                        if (i == input.Length - 1)
                        {
                            count++;
                            builder.Append(input[i]);
                        }

                        groups.Add(new FlightGroup
                        {
                            PeopleCount = count,
                            Answers     = builder.ToString()
                        });
                        count = 0;
                        builder.Clear();
                    }
                    else
                    {
                        count++;
                        builder.Append(input[i]);
                    }
                }
            });
        }
示例#7
0
 protected override void DoGold()
 {
     PerfMon.Monitor("Calculate", () =>
     {
         Result = adapters.SolveCombinations(0, 0);
     });
 }
示例#8
0
 protected override void DoGold()
 {
     PerfMon.Monitor("Calculate", () =>
     {
         Result = groups.Select(x => x.SameAnswerCount()).Sum();
     });
 }
示例#9
0
        protected override void ParseInput()
        {
            StringBuilder builder = new StringBuilder();

            PerfMon.Monitor("Parse", () => {
                var lines = ReadInput();
                foreach (var line in lines)
                {
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        var passport   = new Passport();
                        var properties = builder.ToString().Split(' ').SelectMany(x => x.Split(':')).ToList();
                        for (int i = 0; i < properties.Count(); i += 2)
                        {
                            passport.Fields.Add(properties[i], properties[i + 1]);
                        }
                        passports.Add(passport);
                        builder = new StringBuilder();
                    }
                    else
                    {
                        if (builder.Length > 0)
                        {
                            builder.Append(" " + line);
                        }
                        else
                        {
                            builder.Append(line);
                        }
                    }
                }
            });
        }
示例#10
0
        protected override void Draw(GameTime gameTime)
        {
            PerfMon.DrawStarted();

            this.GraphicsDevice.Clear(Color.CornflowerBlue);

            this.spriteBatch.Begin(SpriteSortMode.FrontToBack);

            var sprites   = new Span <SpriteComponent>(Scene.SpriteComponents);
            var positions = new Span <PositionComponent>(Scene.PositionComponents);

            for (int i = 0; i < Scene.EntityCount; i++)
            {
                var texture2D = this.texture2Ds[sprites[i].Index];
                var color     = new Color(sprites[i].ColorR, sprites[i].ColorG, sprites[i].ColorB, sprites[i].Alpha);
                var origin    = new Vector2(texture2D.Width / 2, texture2D.Height / 2);
                this.spriteBatch.Draw(texture2D, positions[i].Value, null, color, 0.0f, origin, Vector2.One, SpriteEffects.None, sprites[i].Index);
            }

            this.spriteBatch.End();

            base.Draw(gameTime);

            PerfMon.DrawFinished();
        }
示例#11
0
 protected override void DoGold()
 {
     PerfMon.Monitor("Calculate", () =>
     {
         Result = encoder.ContiguousSet();
     });
 }
示例#12
0
        public Report Evaluate(IEnumerable <StockHandle> stocks, DateTime dateUnderAnalysis)
        {
            // XXX: system is only created to get the name for the report
            var system  = myTradingSystemBuilder();
            var report  = new BackTestingReport(system.Name, dateUnderAnalysis);
            var lockObj = new object();

            Parallel.ForEach(stocks, stock =>
            {
                using (PerfMon.Profile("Evaluating stock: {0}", stock.Isin))
                {
                    lock ( lockObj )
                    {
                        system = myTradingSystemBuilder();
                    }

                    var systemResult  = system.Evaluate(stock, dateUnderAnalysis);
                    var tradingResult = PerformBackTesting(systemResult);

                    lock ( lockObj )
                    {
                        report.AddResult(tradingResult);
                    }
                }
            });

            return(report);
        }
示例#13
0
        protected override void DoGold()
        {
            PerfMon.Monitor("Calculate", () =>
            {
                var res = new List <long>();
                foreach (var line in lines)
                {
                    var trimmedLine            = line.Replace(" ", "");
                    Stack <string> calculation = new Stack <string>();
                    foreach (var c in trimmedLine)
                    {
                        calculation.Push(c.ToString());
                        if (c == ')')
                        {
                            var poppedChar  = default(string);
                            StringBuilder a = new StringBuilder();
                            while (poppedChar != "(")
                            {
                                calculation.TryPop(out poppedChar);
                                a.Insert(0, poppedChar);
                                if (poppedChar == "(")
                                {
                                    var result = CalcString2(a.ToString().Substring(1, a.Length - 2));
                                    calculation.Push(result.ToString());
                                }
                            }
                        }
                    }

                    res.Add(CalcString2(calculation.Reverse().Aggregate((a, b) => a + b)));
                }

                Result = res.Sum();
            });
        }
示例#14
0
 protected override void DoSilver()
 {
     ParseInput();
     PerfMon.Monitor("Calculate", () =>
     {
         Result = passes.Select(x => x.GetSeatId()).Max();
     });
 }
示例#15
0
 protected override void DoGold()
 {
     ParseInput();
     PerfMon.Monitor("Calculate", () =>
     {
         Result = positions.Select(x => x.CalculateTrees()).Aggregate((x, y) => x * y);
     });
 }
示例#16
0
 protected override void DoSilver()
 {
     ParseInput();
     PerfMon.Monitor("Calculate", () =>
     {
         Result = groups.Select(x => x.Answers.Distinct().Count()).Sum();
     });
 }
示例#17
0
 static void Main(string[] args)
 {
     PerfMon.Monitor("DayTotal", () =>
     {
         var solution = new Solution();
         solution.Solve();
     });
 }
示例#18
0
        public override void Initialize(InitializeParameters p)
        {
            if (EnableTrace)
            {
                this.trace = new List <Tuple <double, double> >(2048);
            }

            if (!string.IsNullOrEmpty(this.From))
            {
                // Use the From/To properties
                this.CreateSubcomponents();
                this.Subcomponents.Add(new XKeyFrame()
                {
                    Time = "0", Value = this.From, Smoothing = this.Smoothing
                });
                this.Subcomponents.Add(new XKeyFrame()
                {
                    Time = this.Duration, Value = this.To, Smoothing = this.Smoothing
                });
            }

            base.Initialize(p);

            PerfMon.Start("Other-Ani");

            // get targets
            GenerateTargets();
            startValues = new List <double?>(new double?[targets.Count]);

            // collect keyFrames and check for consistency
            keyFrames = this.GetComponents <XKeyFrame>().ToList();
            if (keyFrames.Any(k => k.CurveKeys.Count != targets.Count))
            {
                throw new InvalidOperationException("Number of values in key frames must match number of targets.");
            }
            if (keyFrames.Count < 2)
            {
                throw new InvalidOperationException("Number of key frames must be 2 or more.");
            }
            lastFrame = keyFrames[keyFrames.Count - 1];

            // create curves
            curves = new List <TimeCurve>(targets.Count);
            for (int i = 0; i < targets.Count; i++)
            {
                var curve = new TimeCurve();
                curve.PostLoop = this.Autoreverse ? CurveLoopType.Oscillate : CurveLoopType.Cycle;
                curve.PreLoop  = this.Autoreverse ? CurveLoopType.Oscillate : CurveLoopType.Cycle;

                for (int j = 0; j < keyFrames.Count; j++)
                {
                    curve.Keys.Add(keyFrames[j].CurveKeys[i]);
                }

                curves.Add(curve);
            }
            PerfMon.Stop("Other-Ani");
        }
示例#19
0
 protected override void DoGold()
 {
     PerfMon.Monitor("Calculate", () =>
     {
         var allPasses  = passes.Select(x => x.GetSeatId()).OrderBy(x => x);
         var allNumbers = Enumerable.Range(allPasses.Min(), allPasses.Count());
         Result         = allNumbers.Except(allPasses).First();
     });
 }
示例#20
0
        protected override void ParseInput()
        {
            var lines = ReadInput();

            PerfMon.Monitor("Parse", () =>
            {
                encoder.Cypher = lines.Select(x => long.Parse(x)).ToList();
            });
        }
示例#21
0
        public MultiThreadComponentGame()
        {
            PerfMon.InitializeStarted();

            this.graphics = new GraphicsDeviceManager(this);
            this.Content.RootDirectory = "Content";
            this.IsMouseVisible        = true;
            this.IsFixedTimeStep       = false;
        }
示例#22
0
        protected override void DoSilver()
        {
            ParseInput();
            encoder.Preamble = 25;

            PerfMon.Monitor("Calculate", () =>
            {
                Result = encoder.FindBadNumber();
            });
        }
示例#23
0
文件: XDo.cs 项目: valsavva/dynacat
        public override void Initialize(InitializeParameters p)
        {
            base.Initialize(p);

            PerfMon.Start("Other-Do");

            actions = Compiler.CompileStatements(this, this.Action);

            PerfMon.Stop("Other-Do");
        }
示例#24
0
        public static List <IAction> CompileStatements(XObject currentObject, string text)
        {
            PerfMon.Start("CompileStatements");

            Instance.Initialize(currentObject, text);
            var result = Instance.CompileStatements();

            PerfMon.Stop("CompileStatements");

            return(result);
        }
示例#25
0
        protected override void DoSilver()
        {
            PerfMon.Monitor("Parse", () =>
            {
                ParseInput();
            });

            PerfMon.Monitor("Calculate", () =>
            {
                Result = bags.Select(x => FindGold(x)).Count(x => x == true);
            });
        }
示例#26
0
        protected override void DoSilver()
        {
            PerfMon.Monitor("Parse", () =>
            {
                ParseInput();
            });

            PerfMon.Monitor("Calculate", () =>
            {
                Result = adapters.CountDifferences();
            });
        }
示例#27
0
        protected override void DoGold()
        {
            PerfMon.Monitor("Parse", () => ParseInput());

            PerfMon.Monitor("Calculate", () =>
            {
                var wrongNumbers = new List <long[]>();
                nearbyTickets.ForEach(x =>
                {
                    var remove = false;
                    foreach (var number in x)
                    {
                        if (!rules.Any(y => (y.LowerValues.Item1 <= number && number <= y.LowerValues.Item2) || (y.HigherValues.Item1 <= number && number <= y.HigherValues.Item2)))
                        {
                            remove = !remove;
                        }
                    }
                    if (remove)
                    {
                        wrongNumbers.Add(x);
                    }
                });
                wrongNumbers.ForEach(x => nearbyTickets.Remove(x));

                for (int i = 0; i < nearbyTickets[0].Length; i++)
                {
                    var valuesOfOneField = nearbyTickets.Select(x => x[i]);
                    var matches          = new List <string>();
                    foreach (var rule in rules)
                    {
                        //if (rule.Any(y => (y.LowerValues.Item1 <= number && number <= y.LowerValues.Item2) || (y.HigherValues.Item1 <= number && number <= y.HigherValues.Item2)))
                        if (valuesOfOneField.All(y => (rule.LowerValues.Item1 <= y && y <= rule.LowerValues.Item2) || (rule.HigherValues.Item1 <= y && y <= rule.HigherValues.Item2)))
                        {
                            matches.Add(rule.Name);
                        }
                    }

                    allCombis.Add(i, matches);
                }

                ruleOrder  = Filter(allCombis);
                var result = (long)1;
                for (int i = 0; i < ruleOrder.Count; i++)
                {
                    if (ruleOrder[i].IndexOf("departure") != -1)
                    {
                        result *= myTicket[i];
                    }
                }

                Result = result;
            });
        }
示例#28
0
        protected override void LoadContent()
        {
            var perfSpriteBatch = new SpriteBatch(this.GraphicsDevice);
            var font            = this.Content.Load <SpriteFont>(nameof(Fonts.Consolas));

            spriteBatch = new SpriteBatch(GraphicsDevice);

            this.texture2Ds[Sprites.Dot]    = Content.Load <Texture2D>(nameof(Sprites.Dot));
            this.texture2Ds[Sprites.Bubble] = Content.Load <Texture2D>(nameof(Sprites.Bubble));

            PerfMon.InitializeFinished(perfSpriteBatch, font);
        }
示例#29
0
        protected override void ParseInput()
        {
            PerfMon.Monitor("Parse", () =>
            {
                var lines = ReadInput();
                var area  = new List <char[]>();
                // Create Area
                for (int i = 0; i < lines.Count(); i++)
                {
                    area.Add(lines[i].ToCharArray());
                }

                // Create MoveSettings
                positions = new List <Area>()
                {
                    new Area
                    {
                        Map      = area,
                        Settings = new MoveSettings {
                            Right = 1, Down = 1
                        }
                    },
                    new Area
                    {
                        Map      = area,
                        Settings = new MoveSettings {
                            Right = 3, Down = 1
                        }
                    },
                    new Area
                    {
                        Map      = area,
                        Settings = new MoveSettings {
                            Right = 5, Down = 1
                        }
                    },
                    new Area
                    {
                        Map      = area,
                        Settings = new MoveSettings {
                            Right = 7, Down = 1
                        }
                    },
                    new Area
                    {
                        Map      = area,
                        Settings = new MoveSettings {
                            Right = 1, Down = 2
                        }
                    }
                };
            });
        }
示例#30
0
        private Report RunBackTesting(Func <TradingSystem> tradingSystemBuilder)
        {
            using (PerfMon.Profile("Performing back-testing"))
            {
                var stockListBuilder = new StockListBuilder();
                stockListBuilder.Add(StockArgs.Catalog);

                var task   = new BackTestingTask(tradingSystemBuilder, new DibaBroker());
                var report = task.Evaluate(stockListBuilder.Stocks, DateTime.Today.GetMostRecentTradingDay());

                return(report);
            }
        }