We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I got a solution but it appears to runs to timeout when I run it on 3000 input. I mean this is the best I've comeup with:
IEnumerable<IEnumerable<int>>combinations=l.DifferentCombinations(6);varnumberOfSquares=newConcurrentBag<IEnumerable<int>>();IEnumerable<IEnumerable<int>>combs=combinations.FilterBy();foreach(IEnumerable<int>combincombs){IEnumerable<int>combination=comb.ToList();varsum=combination.Sum();// find pair of 4 that each pair would be equalvarnumber=combination.FirstOrDefault(x=>x*4==sum);varrest=combination.Where(x=>x!=number).ToArray();intcount=combination.Count(x=>x==number);if(number==rest.Sum()/count){varrestOfComb=rest.DifferentCombinations(count).FirstOrDefault(enumerable=>number==enumerable.Sum());if(restOfComb!=null){if(numberOfSquares.Contains(combination)){return;}numberOfSquares.Add(combination);}}else{if(number==rest.Sum()){numberOfSquares.Add(combination);}}}Console.WriteLine(numberOfSquares.Count);
What confuses me is this:Note: Two ways are distinct if they use at least one different stick. As there are choices of sticks, we must determine which combinations of sticks can build a square.
It is implying that I can even introduce better condition. Can you please help me with better understand why is n important? It doesn't make any sence to me since you can get that number from number of sticks. Should this be run in parallel? Because when I run all testcases some fail althouth if you run them separatly they will pass.
New Year Present
You are viewing a single comment's thread. Return to all comments →
I got a solution but it appears to runs to timeout when I run it on 3000 input. I mean this is the best I've comeup with:
What confuses me is this:Note: Two ways are distinct if they use at least one different stick. As there are choices of sticks, we must determine which combinations of sticks can build a square. It is implying that I can even introduce better condition. Can you please help me with better understand why is n important? It doesn't make any sence to me since you can get that number from number of sticks. Should this be run in parallel? Because when I run all testcases some fail althouth if you run them separatly they will pass.