Ejemplo n.º 1
0
            internal List <AdapterArrangement> ComputeArrangements()
            {
                int previousJoltage      = 0;
                AdapterArrangement first = new AdapterArrangement(new List <int> {
                    previousJoltage
                });
                Dictionary <string, AdapterArrangement> arrangements = new Dictionary <string, AdapterArrangement> {
                    { first.Key, first }
                };

                foreach (int joltage in joltages)
                {
                    List <AdapterArrangement> newArrangements = new List <AdapterArrangement>();
                    foreach (string key in arrangements.Keys)
                    {
                        AdapterArrangement arrangement = arrangements[key];
                        newArrangements.AddRange(arrangement.NewArrangements(joltage));
                        if (arrangement.CanAppend(joltage))
                        {
                            arrangement.Append(joltage);
                        }
                    }
                    foreach (AdapterArrangement newArrangement in newArrangements)
                    {
                        if (!arrangements.ContainsKey(newArrangement.Key))
                        {
                            arrangements.Add(newArrangement.Key, newArrangement);
                        }
                    }
                    previousJoltage = joltage;
                }
                return(arrangements.Select(x => x.Value).ToList());
            }
Ejemplo n.º 2
0
            internal List <AdapterArrangement> NewArrangements(int joltage)
            {
                List <AdapterArrangement> newArrangements = new List <AdapterArrangement>();
                AdapterArrangement        testArrangement = new AdapterArrangement(arrangement);

                testArrangement.RemoveLast();
                while (testArrangement.ArrangementCount() > 0)
                {
                    if (!testArrangement.CanAppend(joltage))
                    {
                        break;
                    }
                    AdapterArrangement newArrangement = new AdapterArrangement(testArrangement.arrangement);
                    newArrangement.Append(joltage);
                    newArrangements.Add(newArrangement);
                    testArrangement.RemoveLast();
                }
                return(newArrangements);
            }