Ejemplo n.º 1
0
        private IEnumerable <List <LineVariant> > GetVariantsWithSkippingGroup(int nextGroupIndex, int groupsCount,
                                                                               int iteration,
                                                                               IReadOnlyCollection <LineNumber> numbers, GroupVariant currentGroupVariant)
        {
            var variantsWithSkippingGroups = new List <List <LineVariant> >();

            for (var i = nextGroupIndex + 1; i < groupsCount; i++)
            {
                var lineVariantWithSkipp = GetLineVariants(groupsCount, numbers.TakeLast(iteration).ToList(), i);
                variantsWithSkippingGroups.Add(lineVariantWithSkipp);
            }

            foreach (var variant in variantsWithSkippingGroups.SelectMany(variants => variants))
            {
                variant.Variants.Add(currentGroupVariant);
            }

            return(variantsWithSkippingGroups);
        }
Ejemplo n.º 2
0
        private List <LineVariant> GetLineVariants(int groupsCount, IReadOnlyCollection <LineNumber> numbers,
                                                   int currentGroupIndex)
        {
            var resultLineVariants = new List <LineVariant>();

            if (currentGroupIndex >= groupsCount)
            {
                return(new List <LineVariant>());
            }

            for (var j = 0; j < numbers.Count; j++)
            {
                var groupVariants = new List <GroupVariant>();

                var groupVariant = new GroupVariant
                {
                    GroupIndex     = currentGroupIndex,
                    NumbersIndexes = numbers.Take(numbers.Count - j).Select(x => x.NumberIndex).ToList()
                };

                if (j == 0)
                {
                    groupVariants.Add(groupVariant);

                    resultLineVariants.Add(new LineVariant
                    {
                        Variants = groupVariants
                    });

                    continue;
                }


                var nextGroupIndex = currentGroupIndex + 1;

                var variantsWithoutSkippingGroups = GetLineVariants(groupsCount,
                                                                    numbers.TakeLast(j).ToList(), nextGroupIndex);

                var variantsWithSkippingGroups = GetVariantsWithSkippingGroup(nextGroupIndex, groupsCount, j,
                                                                              numbers, groupVariant);

                resultLineVariants.AddRange(variantsWithSkippingGroups.SelectMany(x => x));

                if (!variantsWithoutSkippingGroups.Any())
                {
                    continue;
                }

                groupVariants.AddRange(variantsWithoutSkippingGroups.FirstOrDefault()?.Variants !);

                var variantsToAdd = variantsWithoutSkippingGroups.Skip(1).ToList();

                foreach (var variant in variantsToAdd)
                {
                    variant.Variants.Add(groupVariant);
                }

                resultLineVariants.AddRange(variantsToAdd.Select(variant => new LineVariant
                {
                    Variants = variant.Variants
                }));

                groupVariants.Add(groupVariant);

                resultLineVariants.Add(new LineVariant
                {
                    Variants = groupVariants
                });
            }

            return(resultLineVariants);
        }