Esempio n. 1
0
        public bool IsStronglyConnected(List <int>[] graph)
        {
            int v = graph.Length;

            bool[] vs = new bool[v];

            DFSUtil(graph, 0, vs);

            if (vs.Any(s => !s))
            {
                return(false);
            }

            var tGraph = GraphListHelper.GetTransposeGraph(graph);

            for (int i = 0; i < v; i++)
            {
                vs[i] = false;
            }

            DFSUtil(tGraph, 0, vs);

            if (vs.Any(s => !s))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        private void PrintTable(List <string[]> table, IBenchmarkLogger logger, string[] columnsToAlwaysShow)
        {
            if (table.Count == 0)
            {
                logger.WriteLineError("There are no found benchmarks");
                logger.NewLine();
                return;
            }
            int rowCount = table.Count, colCount = table[0].Length;
            var columnsToShowIndexes = columnsToAlwaysShow.Select(col => Array.IndexOf(table[0], col));

            int[]  widths  = new int[colCount];
            bool[] areSame = new bool[colCount];
            for (int colIndex = 0; colIndex < colCount; colIndex++)
            {
                areSame[colIndex] = rowCount > 2 && colIndex < colCount - 3;
                for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
                {
                    widths[colIndex] = Math.Max(widths[colIndex], table[rowIndex][colIndex].Length + 1);
                    if (rowIndex > 1 && table[rowIndex][colIndex] != table[1][colIndex])
                    {
                        areSame[colIndex] = false;
                    }
                }
            }
            if (areSame.Any(s => s))
            {
                for (int colIndex = 0; colIndex < colCount; colIndex++)
                {
                    if (areSame[colIndex] && columnsToShowIndexes.Contains(colIndex) == false)
                    {
                        logger.WriteInfo($"{table[0][colIndex]}={table[1][colIndex]}  ");
                    }
                }
                logger.NewLine();
            }

            table.Insert(1, widths.Select(w => new string('-', w)).ToArray());
            foreach (var row in table)
            {
                for (int colIndex = 0; colIndex < colCount; colIndex++)
                {
                    if (!areSame[colIndex] || columnsToShowIndexes.Contains(colIndex))
                    {
                        logger.WriteStatistic(row[colIndex].PadLeft(widths[colIndex], ' ') + " |");
                    }
                }
                logger.NewLine();
            }

            if (areSame.Any(s => s))
            {
                logger.NewLine();
            }
        }
Esempio n. 3
0
        private bool AdjustStringMembers(TypeGenerator generator, FileAnalyzer analyzer)
        {
            analyzer.Stream.Position = 0;

            var enumerableType = typeof(StorageEnumerable <>).MakeGenericType(analyzer.RecordType);
            var enumerable     = (IEnumerable)Activator.CreateInstance(enumerableType, analyzer.Stream, analyzer.Options);

            var isValidString = new bool[analyzer.Members.Members.Count];

            for (var itr = 0; itr < isValidString.Length; ++itr)
            {
                isValidString[itr] = false;
            }

            foreach (var node in enumerable)
            {
                var memberIndex = 0;
                foreach (var exMemberInfo in analyzer.Members.Members)
                {
                    if (memberIndex == analyzer.Members.IndexColumn)
                    {
                        ++memberIndex;
                        continue;
                    }

                    var memberInfo  = (PropertyInfo)exMemberInfo.MemberInfo;
                    var memberValue = memberInfo.GetValue(node);

                    if (exMemberInfo.Type == typeof(string))
                    {
                        isValidString[memberIndex] = exMemberInfo.MappedTo.BitSize > 16 && memberValue != null;
                    }

                    ++memberIndex;
                }
            }

            for (var itr = 0; itr < isValidString.Length; ++itr)
            {
                if (!isValidString[itr])
                {
                    generator.GetMember(itr).Type = typeof(int);
                }
            }

            if (isValidString.Any())
            {
                generator.Generate();
            }

            return(isValidString.Any());
        }
#pragma warning restore

        public void Evaluate(int SpreadMax)
        {
            SpreadMax = FInput.IsAnyInvalid() ? 0 : FInput.SliceCount;

            if (SpreadMax <= 0)
            {
                FMatch.FlushNil();
                FOutput.FlushNil();

                return;
            }
            FMatch.SliceCount = FOutput.SliceCount = 0;

            foreach (var message in FInput)
            {
                var match = new bool[FFilter.SliceCount];
                for (int i = 0; i < FFilter.SliceCount; i++)
                {
                    match[i] = message.Fields.Contains(FFilter[i]);
                }

                if (match.Any())
                {
                    FOutput.Add(message);
                    FMatch.AddRange(match);
                }
            }

            FOutput.Flush();
            FMatch.Flush();
        }
Esempio n. 5
0
        static void Solve()
        {
            var a = GetInts()[0];
            var i = 1;

            while (true)
            {
                var bools = new bool[9];
                while (bools.Any(z => !z))
                {
                    Console.WriteLine($"{i + 1} 2");
                    Console.Out.Flush();
                    var xs = GetInts();
                    if (xs[0] == 0 && xs[1] == 0)
                    {
                        return;
                    }
                    if (xs[0] == -1 && xs[1] == -1)
                    {
                        return;
                    }
                    var row    = xs[0] - i;
                    var column = xs[1] - 1;
                    bools[row * 3 + column] = true;
                }
                i += 3;
            }
        }
Esempio n. 6
0
        public static bool AllCovered(List <Period> periodList, DateTime begin, DateTime end)
        {
            int diff = (int)(end.Date - begin.Date).TotalDays;

            if (diff <= 0)
            {
                return(true);
            }
            bool[] covered = new bool[diff];

            for (int i = 0; i < diff; i++)
            {
                // Get the list of periods for that day and only that day
                // It's a list because multiple periods can be at the same begin-end datetimes but with different days
                IEnumerable <Period> periods = periodList.Where(p => begin >= p.Begin && begin <= p.End && p.IsClosed == false);
                foreach (Period cur in periods)
                {
                    // Check if that day is covered
                    if (((int)cur.Days & days[(int)(begin.DayOfWeek)]) == days[(int)(begin.DayOfWeek)])
                    {
                        covered[i] = true;
                    }
                }
                begin = begin.AddDays(1);
            }
            return(!covered.Any(p => p == false));
        }
Esempio n. 7
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.P))
        {
            //AudioPeer.Pause();
            stopped = !stopped;
        }
        if (stopped)
        {
            return;
        }

        timeLimit -= Time.deltaTime;

        if (timeLimit < 0)
        {
            var graces = new bool[8];
            for (int i = 0; i < 8; i++)
            {
                  {
                    graces[i] = AudioPeer.audioBand[i] > tresholdDown && AudioPeer.audioBand[i] < tresholdUp;
                }
            }
            if (graces.Any(x => x == true))
            {
                SpawnWall(graces);
            }
            timeLimit = minTimeBetweenWalls;
        }
    }
Esempio n. 8
0
        public int Solution(int[] A)
        {
            // write your code in C# 5.0 with .NET 4.5 (Mono)
            if (A.Length == 1)
            {
                return(A[0] == 1 ? 1 : 0);
            }

            int maxNumber = A.Length;

            var existing = new bool[maxNumber + 1];

            existing[0] = true;

            foreach (int number in A)
            {
                if (number < A.Length + 1)
                {
                    existing[number] = true;
                }
                else
                {
                    return(0);
                }
            }

            if (existing.Any(exist => !exist))
            {
                return(0);
            }

            return(1);
        }
Esempio n. 9
0
        private PerformanceHeartbeat[] MatchEquivalentHeartbeats(PerformanceHeartbeat[] expected)
        {
            return(Match.Create <PerformanceHeartbeat[]>(actual =>
            {
                if (expected.Length != actual.Length)
                {
                    return false;
                }

                bool[] matches = new bool[5];
                for (int i = 0; i < actual.Length; ++i)
                {
                    matches[0] = expected[i].PartitionCount == actual[i].PartitionCount;
                    matches[1] = expected[i].ControlQueueLatencies.SequenceEqual(actual[i].ControlQueueLatencies);
                    matches[2] = expected[i].ControlQueueLengths.SequenceEqual(actual[i].ControlQueueLengths);
                    matches[3] = expected[i].WorkItemQueueLength == actual[i].WorkItemQueueLength;
                    matches[4] = expected[i].WorkItemQueueLatency == actual[i].WorkItemQueueLatency;

                    if (matches.Any(m => m == false))
                    {
                        return false;
                    }
                }

                return true;
            }));
        }
Esempio n. 10
0
        private static bool[][] Evolve(bool[][] currentBoardState, bool isToroidal)
        {
            var rowCount      = currentBoardState.Length;
            var newBoardState = new bool[rowCount][];

            if (newBoardState.Any())
            {
                var columnCount = currentBoardState[0].Length;

                for (var row = 0; row < rowCount; row++)
                {
                    newBoardState[row] = new bool[columnCount];

                    for (var cell = 0; cell < columnCount; cell++)
                    {
                        var liveNeighbors = GetLiveNeighborCount(row, cell, currentBoardState, isToroidal);

                        //Apply the Game of Life Rules
                        //Rules are:
                        //1. Any live cell with two or three neighbors survives.
                        //2. Any dead cell with three live neighbors becomes a live cell.
                        //3. All other live cells die in the next generation. Similarly, all other dead cells stay dead.

                        newBoardState[row][cell] = currentBoardState[row][cell]
                            ? !((liveNeighbors < 2) || (liveNeighbors > 3))
                            : liveNeighbors == 3;
                    }
                }
            }

            return(newBoardState);
        }
Esempio n. 11
0
        public bool[] GetRemainingRows()
        {
            var remainingRows = new bool[PreprocessingData.Rows];

            if (ActiveFilters.Any())
            {
                var filterResults    = ActiveFilters.Select(f => f.Check()).ToList();
                var rowFilterResults = new bool[filterResults.Count];
                for (int row = 0; row < remainingRows.Length; row++)
                {
                    for (int i = 0; i < filterResults.Count; i++)
                    {
                        rowFilterResults[i] = filterResults[i][row];
                    }

                    remainingRows[row] = IsAndCombination
            ? rowFilterResults.All(x => x)
            : rowFilterResults.Any(x => x);
                }
            }
            else
            {
                // if not filters active => all rows are remaining
                for (int i = 0; i < remainingRows.Length; i++)
                {
                    remainingRows[i] = true;
                }
            }
            return(remainingRows);
        }
Esempio n. 12
0
        private static ulong[] FindPatterns()
        {
            ulong[] uOffsets  = new ulong[4];
            ulong   lpAddress = 0x140004000;

            bool[] found = new bool[4] {
                false, false, false, false
            };
            do
            {
                if (VirtualQueryEx(game.Handle, (IntPtr)(long)lpAddress, out MEMORY_BASIC_INFORMATION64 lpBuffer, (uint)Marshal.SizeOf(typeof(MEMORY_BASIC_INFORMATION64))) > 0 && lpBuffer.RegionSize != 0)
                {
                    byte[] buffer = new byte[lpBuffer.RegionSize];
                    ReadProcessMemory(game.Handle, (IntPtr)(long)lpBuffer.BaseAddress, buffer);
                    for (int i = 0; i < 4; ++i)
                    {
                        if (found[i])
                        {
                            continue;
                        }
                        if (uOffsets[i] == 0)
                        {
                            int index = FindSubArrayIndex(buffer, patterns[i]);
                            if (index >= 0)
                            {
                                uOffsets[i] = lpBuffer.BaseAddress + (ulong)index;
                                found[i]    = true;
                            }
                        }
                    }
                }
            } while (lpAddress < 0x145000000 && found.Any(x => !x));
            return(uOffsets);
        }
Esempio n. 13
0
    private bool IngredientMatch(IngredientType[] ing1, IngredientType[] ing2)
    {
        if (ing1 == null || ing2 == null || ing1.Length != ing2.Length)
        {
            return(false);
        }

        // we want to flag the elements in the second array that have been already been matched with one in the first array
        bool[] matchedIngredients = new bool[ing2.Length];

        // for each ingredient in first array, look for a match in the second array
        for (int i = 0; i < ing1.Length; i++)
        {
            IngredientType currentIngredient = ing1[i];

            for (int j = 0; j < ing2.Length; j++)
            {
                if (!matchedIngredients[j] && currentIngredient == ing2[j])
                {
                    matchedIngredients[j] = true;
                    break;
                }
            }
        }

        // if any of the ingredients of the second array wasn't matched, return false, otherwise it's a match
        return(!matchedIngredients.Any(m => !m));

        // TODO: can be improved so that it returns false exactly after one element wasn't found... no need to keep matching.
    }
Esempio n. 14
0
        /// <summary>
        /// Fetches tasks that are waiting to be processed
        /// </summary>
        /// <param name="sender">the event-sender</param>
        /// <param name="e">event information</param>
        private void FetchMoreTasks(object sender, GetMoreTasksEventArgs e)
        {
            TPackage package;

            if (packages[e.Priority].TryTake(out package))
            {
                IProcessTask[] items = package.GetTasks();
                lock (workingPackages)
                {
                    package.PackageFinished  += PackageFinished;
                    package.DemandForRequeue += DemandForRequeue;
                    workingPackages.Add(package);
                }

                bool[] ok = new bool[items.Length];
                while (ok.Any(n => !n))
                {
                    for (int index = 0; index < items.Length; index++)
                    {
                        IProcessTask item = items[index];
                        ok[index] = processor.EnqueueTask((TTask)item);
                    }
                }
            }
        }
Esempio n. 15
0
        public bool CheckingWhichJobsDetailsCanBeDisplayedInUserDetailsWindow(User _userWhoWantsToWatch, out bool[] matches)
        {
            matches = new bool[_checksIfUserCanSeeUserDetails.Length];

            for (int i = 0; i < _checksIfUserCanSeeUserDetails.Length; i++)
            {
                var funcForUser    = _checksIfUserCanSeeUserDetails[i];
                var funcForWatcher = _checksIfUserWhoWatchCanSeeUsersDetails[i];
                if (_userWhoWantsToWatch == null)
                {
                    funcForWatcher = u => true;
                }

                if (funcForUser(this) && funcForWatcher(_userWhoWantsToWatch))
                {
                    matches[i] = true;
                }
                else
                {
                    matches[i] = false;
                }
            }

            return(matches.Any(b => b));
        }
        public static (bool result, Dictionary <int, int> value) IsSeriesTestPassed(string bbsString)
        {
            FillSeries();

            string series = string.Empty;

            foreach (var letter in bbsString)
            {
                if (letter != '0')
                {
                    series += letter;
                }
                else if (!string.IsNullOrEmpty(series))
                {
                    seriesSet[series.Length >= 6 ? 6 : series.Length]++;
                    series = string.Empty;
                }
            }

            bool[] summary = new bool[6];

            summary[0] = seriesSet[1].IsInRange(2315, 2685);
            summary[1] = seriesSet[2].IsInRange(1114, 1386);
            summary[2] = seriesSet[3].IsInRange(527, 723);
            summary[3] = seriesSet[4].IsInRange(240, 384);
            summary[4] = seriesSet[5].IsInRange(103, 209);
            summary[5] = seriesSet[6].IsInRange(103, 209);

            return(!summary.Any(s => !s), seriesSet);
        }
Esempio n. 17
0
        int GetCost(Diff diff, Point[] points)
        {
            var seen    = new bool[points.Length];
            var current = points[0];

            seen[0] = true;
            var cost = 1;

            while (seen.Any(b => !b))
            {
                var next = FindNext(diff, current, points, seen);
                if (next != -1)
                {
                    current    = points[next];
                    seen[next] = true;
                }
                else
                {
                    cost++;
                    for (int i = 0; i < seen.Length; i++)
                    {
                        if (!seen[i])
                        {
                            current = points[i];
                            seen[i] = true;
                            break;
                        }
                    }
                }
            }

            return(cost);
        }
Esempio n. 18
0
#pragma warning restore 1591 // Xml Comments

        void ScheduleOperations(Task task, Action <Task> taskDone)
        {
            _taskOperationIds[task] = new Guid[task.Operations.Length];
            var operationsDone = new bool[task.Operations.Length];

            for (var operationIndex = 0; operationIndex < task.CurrentOperation; operationIndex++)
            {
                operationsDone[operationIndex] = true;
            }

            for (var operationIndex = task.CurrentOperation; operationIndex < task.Operations.Length; operationIndex++)
            {
                ScheduleOperation(task, operationsDone, operationIndex, taskDone);
            }

            if (!_tasks.Contains(task))
            {
                StopOperationsForTask(task);
            }

            if (!operationsDone.Any(b => b == false))
            {
                _taskOperationIds.Remove(task);
            }
        }
Esempio n. 19
0
        public static IEnumerable <IEnumerable <int> > Find(int[] containers)
        {
            bool[] indexes = new bool[containers.Length];

            do
            {
                int  currentIndex = indexes.Length - 1;
                bool overflow     = false;

                do
                {
                    indexes[currentIndex] = !indexes[currentIndex];
                    if (!indexes[currentIndex])
                    {
                        overflow = true;
                        --currentIndex;
                        if (currentIndex < 0)
                        {
                            break;
                        }
                    }
                    else
                    {
                        overflow = false;
                    }
                } while (overflow);

                IEnumerable <int> used = containers.Zip(indexes, (c, i) => (c: c, i: i)).Where(x => x.i).Select(x => x.c);
                if (used.Sum() == 150)
                {
                    yield return(used);
                }
            } while (indexes.Any(x => !x));
        }
Esempio n. 20
0
        public int EvaluateUnlessWithMigration(double targetValue, double mutationMin, double mutationMax, double selectionP = 1)
        {
            var    comm      = Intercommunicator.world;
            double current   = Average();
            int    counter   = 0;
            bool   done      = false;
            bool   totalDone = false;

            bool[] dones = new bool[comm.Size];
            while (current > targetValue)
            {
                comm.Allgather(done, ref dones);
                totalDone = dones.Any(d => d);
                if (totalDone)
                {
                    break;
                }
                Selection(selectionP);
                Crossover();
                Mutation(mutationMin, mutationMax);
                current = Average();
                counter++;
                if (counter % 5 == 0)
                {
                    Migrate(_population.Length / 4);
                }
            }
            done = true;
            if (!totalDone)
            {
                comm.Allgather(done, ref dones);
            }
            return(counter);
        }
Esempio n. 21
0
        public static TaxonomyFieldValueCollection GetTaxonomyFieldValues(TermSet termSet, IEnumerable <string> values, bool addIfDoesNotExist, out bool newTermsAdded)
        {
            TaxonomyFieldValueCollection termValues = TaxonomyFieldControl.GetTaxonomyCollection("");

            newTermsAdded = false;

            if (values != null && values.Count() > 0)
            {
                bool[] newTermAddedResult = new bool[values.Count()];
                termValues.AddRange(values.Where(termValue => termValue != null)
                                    .Select((value, i) =>
                {
                    bool newTermAdded;
                    TaxonomyFieldValue val = GetTaxonomyFieldValue(termSet,
                                                                   value,
                                                                   addIfDoesNotExist,
                                                                   out newTermAdded);
                    newTermAddedResult[i] = newTermAdded;
                    return(val);
                }));
                newTermsAdded = newTermAddedResult.Any(newTermAdded => newTermAdded);
            }

            return(termValues);
        }
Esempio n. 22
0
        private static long CheckMutualExclusion(ILock @lock, int count, int cyclesCount)
        {
            var buckets  = new long[count];
            var finished = new bool[count];
            var total    = 0L;

            ThreadId.ZeroOut();

            var threads = Enumerable.Range(0, count).Select(i =>
            {
                return(new Thread(() =>
                {
                    for (var j = 0; j < cyclesCount; j++)
                    {
                        @lock.Lock();
                        buckets[i]++;
                        total++;
                        @lock.Unlock();
                    }

                    finished[i] = true;
                }));
            });

            foreach (var thread in threads)
            {
                thread.Start();
            }

            while (finished.Any(f => !f))
            {
            }

            return(total);
        }
Esempio n. 23
0
        /// <summary>
        /// Checks to see if a section of cells is valid.  A section of cells would be a single row, single column or single quadrient of cells.
        /// </summary>
        /// <remarks>
        /// All cells must have a value and the values must be unique within the section of cells
        /// </remarks>
        /// <param name="cells"></param>
        /// <returns></returns>
        internal static bool IsValid(IEnumerable <Puzzle.Cell> cells)
        {
            bool[] verifier = new bool[Puzzle.MAX_VALUE];

            /*
             * The idea is simple...
             * Use a verifying array to hold true/false values.
             * Iterate through the section of cells
             * When iterating through the cells array, use the cell's value (minus 1) as the index to the verifier array to set the value to true
             * After the cells has been iterated all the way through, then check the verifier array.
             * If all values are true, then the section of cells is valid
             */

            // Iterate through the section of cells
            foreach (Puzzle.Cell cell in cells)
            {
                if (cell.Value.HasValue)
                {
                    verifier[cell.Value.Value - 1] = true;
                }
            }


            // Check to see if there is any item in the array that is false, if so, then it is not valid
            return(!verifier.Any(x => x == false));
        }
Esempio n. 24
0
        /// <summary>
        /// Tests if the basic conditions for photosynthesis to occur are met
        /// </summary>
        private bool IsSensible()
        {
            var CPath = Canopy.Canopy;
            var temp  = Temperature.AirTemperature;

            bool[] tempConditions = new bool[4]
            {
                temp > pathway.ElectronTransportRateParams.TMax,
                temp <pathway.ElectronTransportRateParams.TMin,
                      temp> pathway.MesophyllCO2ConductanceParams.TMax,
                temp < pathway.MesophyllCO2ConductanceParams.TMin
            };

            bool invalidTemp = tempConditions.Any(b => b == true);
            bool invalidRadn = Radiation.Total <= double.Epsilon;

            if (invalidTemp || invalidRadn)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 25
0
        private bool IsValidRsaHsm()
        {
            // MAY have public key parameters
            if ((N == null && E != null) || (N != null && E == null))
            {
                return(false);
            }

            // MUST NOT have private key parameters, but only ALL or NONE
            var privateParameters = new bool[] { D != null, DP != null, DQ != null, QI != null, P != null, Q != null };

            if (privateParameters.Any((value) => value))
            {
                return(false);
            }

            // MUST have ( T || ( N && E ) )
            var tokenParameters  = T != null;
            var publicParameters = (N != null && E != null);

            if (tokenParameters && publicParameters)
            {
                return(false);
            }

            return(tokenParameters || publicParameters);
        }
Esempio n. 26
0
        static void Main(string[] args)
        {
            var word           = "onomatopoetikon";
            var triedLetters   = new List <char>();
            var visibleLetters = new bool[word.Length];

            while (visibleLetters.Any(v => v == false))
            {
                Console.WriteLine("Gjett ordet eller en bokstav:");

                var guess = Console.ReadLine();

                if (guess.Length > 1 && guess != word)
                {
                    Console.WriteLine("Feil, prøv igjen :P");
                }
                else if (guess.Length > 1 && guess == word)
                {
                    Console.WriteLine("Korrekt! :D");
                    visibleLetters = Enumerable.Repeat(true, visibleLetters.Length).ToArray();
                }
                else if (guess.Length == 1)
                {
                    RevealLetter(ref visibleLetters, word, guess.ToCharArray().First());
                }

                PrintWord(word, visibleLetters);
            }
        }
Esempio n. 27
0
        public bool passwordTester(string password)
        {
            bool[] hasDouble = new bool[6];
            char   lastChar  = password[0];
            char   twoPrev   = ' ';

            if (password.Length != 6)
            {
                return(false);
            }
            for (int i = 1; i < password.Length; i++)
            {
                if (password[i] < lastChar)
                {
                    return(false);
                }
                if (password[i] == lastChar && password[i] != twoPrev)
                {
                    hasDouble[i - 1] = true;
                }
                if (password[i] == lastChar && password[i] == twoPrev)
                {
                    hasDouble[i - 2] = false;
                }
                twoPrev  = lastChar;
                lastChar = password[i];
            }
            return(hasDouble.Any(x => x == true));
        }
Esempio n. 28
0
        private static IEnumerable <IEnumerable <TResult> > ZipIteratorExtended <TIn, TResult>(
            IEnumerable <IEnumerable <TIn> > sequences,
            Func <TIn, TResult> resultSelector)
        {
            var enumerators      = sequences.Select(_ => _.GetEnumerator()).ToList();
            var length           = enumerators.Count;
            var breakEnumerators = new bool[length];

            while (breakEnumerators.Any(_ => !_))
            {
                var result = Enumerable.Empty <TResult>();
                foreach (var i in Enumerable.Range(0, length))
                {
                    if (!enumerators[i].MoveNext())
                    {
                        breakEnumerators[i] = true;
                    }
                    else
                    {
                        result = resultSelector(enumerators[i].Current).Yield().Concat(result);
                    }
                }

                yield return(result);
            }

            enumerators.ForEach(_ => _.Dispose());
        }
Esempio n. 29
0
        public static bool arithmeticExpression(int a, int b, int c)
        {
            var tests = new bool[4] {
                (a + b == c), (a - b == c), (a * b == c), (b * c == a)
            };

            return(tests.Any(x => x == true));
        }
Esempio n. 30
0
        /// <summary>
        /// 深度优先遍历,采用bool数组
        /// </summary>
        /// <param name="rooms"></param>
        /// <returns></returns>
        public bool CanVisitAllRooms_V2(IList <IList <int> > rooms)
        {
            var res = new bool[rooms.Count];

            dfs(rooms, 0, res);

            return(!(res.Any(i => i == false)));
        }