Beispiel #1
0
        public void Distribute()
        {
            var iteration = 0;

            optimalDistribution =
                FibonacciSequenceGenerator.GetRangeOfN(iteration + 1, numberOfOutputBuffers);

            while (BufferIO.InputBufferHasNext() || !optimallyDistributed())
            {
                createNewOptimalDistributionIfNecessary(iteration + 1);
                for (var i = 0; i < optimalDistribution.Length; i++)
                {
                    if (optimalDistribution[i] <= 0)
                    {
                        continue;
                    }
                    BufferIO.WriteNextSeriesToBuffer(i);
                    optimalDistribution[i]--;
                }

                iteration++;
            }

            BufferIO.FlushOutputBuffers();
        }
Beispiel #2
0
        private int[] getDistribution(int series, int buffers)
        {
            var i = 1;

            int[] distribution;
            do
            {
                distribution = fibonacciSequenceGenerator.GetRangeOfN(i++, buffers);
            } while (distribution.Sum() < series);

            return(reverse(distribution));
        }