示例#1
0
 public void UpdateRelationships(ImmutableList <Relationship> rels)
 {
     Rels = rels;
     FriendLabel.Caption = GameFacade.Strings.GetString("f106", "7", new string[] {
         rels.Count(x => x.Relationship_IsOutgoing && x.Relationship_LTR >= 60).ToString(),
         rels.Count(x => x.Relationship_IsOutgoing && x.Relationship_LTR <= -60).ToString()
     });
     RedrawRels();
 }
示例#2
0
        public virtual async Task <TodoSummary> GetSummary(Session session, CancellationToken cancellationToken = default)
        {
            await PseudoGetAllItems(session);

            var count     = _store.Count();
            var doneCount = _store.Count(i => i.IsDone);

            return(new TodoSummary(count, doneCount));
        }
示例#3
0
        /// <summary>
        /// Получает последние записанные итерацию и невязку.
        /// </summary>
        /// <returns>Возвращает текущую итерацию и невязку на ней.</returns>
        public (int currentIter, double residual) GetCurrentState()
        {
            if (!logList.IsEmpty)
            {
                int    iter     = logList.Count() - 1;
                double residual = logList[iter];
                return(iter, residual);
            }

            return(0, 0);
        }
        public void AggregateExample()
        {
            // function fold (or reduce)
            // fold applies a function to each item in the list
            // it takes a list, and returns a single result (not a list)
            // It is an accumulative function
            // for example, SUM totals the 1st and 2nd item
            // then totals that result with the 3rd item and so on...
            //
            // LINQ (Aggregate, Sum, Average)
            // LINQ (Max, Min, Count)

            ImmutableList <int> setA = ImmutableList.Create(5, 4, 1, 3, 9, 8, 6, 7, 2, 12, 24);
            ImmutableList <int> setB =
                ImmutableList.Create(Enumerable.Range(1, 40).Where(x => x % 5 == 0).ToArray());

            // predefined aggregates
            var total = setA.Sum();
            var count = setB.Count();

            var highestNumber = setB.Max();


            // custom aggregate

            var multipleOf = setA.Aggregate((first, second) => first * second);

            // set the initial seed (accumulator value)

            var anotherMultiple = setA.Aggregate(100, (first, second) => first * second);
        }
示例#5
0
        public override string Solve_1()
        {
            int cuplen = cups.Count();
            int curcup = cups.First();

            for (int i = 0; i < 100; i++)
            {
                //Console.WriteLine("Cups: {0}", String.Join(", ", cups));
                var cumpindx = cups.IndexOf(curcup);
                var cup1     = cups[(cumpindx + 1) % cuplen];
                var cup2     = cups[(cumpindx + 2) % cuplen];
                var cup3     = cups[(cumpindx + 3) % cuplen];
                cups = cups.Remove(cup1);
                cups = cups.Remove(cup2);
                cups = cups.Remove(cup3);
                //Console.WriteLine("Take: {0} {1} {2}", cup1, cup2, cup3);
                cumpindx = cups.IndexOf(curcup);
                curcup   = cups[(cumpindx + 1) % (cuplen - 3)];

                var des    = cups[cumpindx] - 1;
                var mincup = cups.Min();
                var maxcup = cups.Max();
                if (des < mincup)
                {
                    des = maxcup;
                }
                while (des == cup1 || des == cup2 || des == cup3)
                {
                    des--;
                    if (des < mincup)
                    {
                        des = maxcup;
                    }
                }
                //Console.WriteLine("Dest: {0}\n", des);
                var newindx = cups.IndexOf(des) + 1;
                if (newindx == cuplen - 3)
                {
                    cups = cups.Add(cup1);
                    cups = cups.Add(cup2);
                    cups = cups.Add(cup3);
                }
                else
                {
                    cups = cups.Insert(newindx, cup3);
                    cups = cups.Insert(newindx, cup2);
                    cups = cups.Insert(newindx, cup1);
                }
            }

            var result = "";

            for (int i = cups.IndexOf(1) + 1; i < cups.IndexOf(1) + cups.Count; i++)
            {
                result += cups[i % cups.Count].ToString();
            }

            return(result);
        }
示例#6
0
文件: Algorithm.cs 项目: speku/MM
 /// <summary>
 /// Generates all possible next states of the given state
 /// </summary>
 /// <param name="currentState"></param>
 /// <returns></returns>
 private static IEnumerable <ImmutableList <int> > NextStates(ImmutableList <int> currentState)
 {
     return
         (currentState.Zip(Range(0, currentState.Count()), (heapSize, index) => new { heapSize, index }).                                                                             // attach indices: [3,2,1] => [(3,0),(2,1),(1,2)]
          Where(heapSizeIndex => heapSizeIndex.heapSize != 0).                                                                                                                        // filter out empty heaps since they can't be modified in order to create a new state
          Select(heapSizeIndex => new { index = heapSizeIndex.index, nextSizes = Range(0, heapSizeIndex.heapSize) }).                                                                 // for each heap, create all possible future heap sizes: [(0,[2,1,0]),(1,[1,0]),(2,[0])] the first element in the tuple is the index within the outer list
          SelectMany(indecesHeapSizes => indecesHeapSizes.nextSizes.Select(nextSize => currentState.RemoveAt(indecesHeapSizes.index).Insert(indecesHeapSizes.index, nextSize))));     // for each possible future heap size of each heap, create the next state with only the size of the particular heap altered. Then, flatten the list to remove one level of nesting: [[2,2,1],[1,2,1],[0,2,1],[3,1,1],[3,0,1],[3,2,0]]
 }
示例#7
0
 public static bool IsEqualTo(this ImmutableList <ParserChar> self, string rhs)
 {
     return(self.Count() != rhs.Length
         ? false
         : self.Zip(rhs.Cast <char>(), (left, right) => left.Value == right)
            .Where(match => match == false)
            .Count() == 0);
 }
    // Preconditions:
    // * items is a sequence of non-negative monotone increasing integers
    // * n is the number of items to be in the subsequence
    // * sum is the desired sum of that subsequence.
    // Result:
    // A sequence of subsequences of the original sequence where each
    // subsequence has n items and the given sum.
    static IEnumerable <ImmutableList <int> > M(ImmutableList <int> items, int sum, int n)
    {
        // Let's start by taking some easy outs. If the sum is negative
        // then there is no solution. If the number of items in the
        // subsequence is negative then there is no solution.

        if (sum < 0 || n < 0)
        {
            yield break;
        }

        // If the number of items in the subsequence is zero then
        // the only possible solution is if the sum is zero.
        if (n == 0)
        {
            if (sum == 0)
            {
                yield return(ImmutableList <int> .Empty);
            }
            yield break;
        }

        // If the number of items is less than the required number of
        // items, there is no solution.

        if (items.Count() < n)
        {
            yield break;
        }

        // We have at least n items in the sequence, and
        // and n is greater than zero.
        int first = items.Head;

        // We need n items from a monotone increasing subsequence
        // that have a particular sum. We might already be too
        // large to meet that requirement:

        if (n * first > sum)
        {
            yield break;
        }

        // There might be some solutions that involve the first element.
        // Find them all.

        foreach (var subsequence in M(items.Tail, sum - first, n - 1))
        {
            yield return(subsequence.Push(first));
        }

        // And there might be some solutions that do not involve the first element.
        // Find them all.
        foreach (var subsequence in M(items.Tail, sum, n))
        {
            yield return(subsequence);
        }
    }
示例#9
0
        private static SabotenCache PrefetchAll(this SabotenCache dataSample, ImmutableList <Tuple <Range, Converter <IEnumerable <double>, IEnumerable <double> > > > dataTransformers)
        {
            for (int featureIndex = 0; featureIndex < dataTransformers.Count(); featureIndex++)
            {
                dataSample = dataSample.Prefetch(featureIndex, dataTransformers[featureIndex]);
            }

            return(dataSample);
        }
示例#10
0
        public static void ReadPrimitiveImmutableListT()
        {
            ImmutableList <int> result = JsonSerializer.Parse <ImmutableList <int> >(Encoding.UTF8.GetBytes(@"[1,2]"));
            int expected = 1;

            foreach (int i in result)
            {
                Assert.Equal(expected++, i);
            }

            result = JsonSerializer.Parse <ImmutableList <int> >(Encoding.UTF8.GetBytes(@"[]"));
            Assert.Equal(0, result.Count());
        }
示例#11
0
        private async ValueTask DownloadAlbumAsync(ImmutableList <MusicInfo> musicInfos)
        {
            _logger.LogInformation("开始下载专辑图像数据...");

            var downloader   = _albumDownloaderList.FirstOrDefault(d => d.DownloaderName == InternalAlbumDownloaderNames.NetEase);
            var warpTask     = new WarpTask(ParallelNumber);
            var warpTaskList = musicInfos.Select(info =>
                                                 warpTask.RunAsync(() => Task.Run(async() => await DownloadAlbumTaskLogicAsync(downloader, info))));

            await Task.WhenAll(warpTaskList);

            _logger.LogInformation($"专辑数据下载完成,成功: {musicInfos.Count(m => m.IsSuccessful)} 失败{musicInfos.Count(m => !m.IsSuccessful)}。");
        }
示例#12
0
        public async Task ReadPrimitiveImmutableListT()
        {
            ImmutableList <int> result = await JsonSerializerWrapperForString.DeserializeWrapper <ImmutableList <int> >(@"[1,2]");

            int expected = 1;

            foreach (int i in result)
            {
                Assert.Equal(expected++, i);
            }

            result = await JsonSerializerWrapperForString.DeserializeWrapper <ImmutableList <int> >(@"[]");

            Assert.Equal(0, result.Count());
        }
示例#13
0
        private static int Part1(ImmutableList <Point> activeCubes)
        {
            var directionVectors3D = (from x in Enumerable.Range(-1, 3)
                                      from y in Enumerable.Range(-1, 3)
                                      from z in Enumerable.Range(-1, 3)
                                      where !(x == 0 && y == 0 && z == 0)
                                      select new Point(new List <int> {
                x, y, z
            }))
                                     .ToImmutableList();

            for (var i = 1; i <= 6; i++)
            {
                activeCubes = GetNewActiveCubes(activeCubes, directionVectors3D);
            }

            return(activeCubes.Count());
        }
示例#14
0
        public void Setup(IEnumerable <DownloadItem> downloadItems)
        {
            // Initialize states
            _downloadItems           = downloadItems.ToImmutableList();
            _totalBytes              = _downloadItems.Sum(item => item.Size);
            _downloadedBytes         = 0;
            _previousDownloadedBytes = 0;

            _totalCount     = _downloadItems.Count();
            _completedCount = 0;
            _failedCount    = 0;

            if (_userCts.IsCancellationRequested)
            {
                _userCts.Dispose();
                _userCts = new CancellationTokenSource();
                _parallelOptions.CancellationToken = _userCts.Token;
            }

            _autoResetEvent.Reset();

            _logService.Info(nameof(DownloadService), $"New downloads added. Count: {_totalCount} Size: {_totalBytes} bytes");
        }
 public int Count(Expression <Func <Category, bool> > predicate) => _categories.Count(predicate.Compile());
 public int Count(Expression <Func <Runner, bool> > predicate) => _runners.Count(predicate.Compile());
示例#17
0
 private int PartOne(ImmutableList <ImmutableDictionary <string, string> > input) =>
 input.Count(ContainsRequiredFields);