Esempio n. 1
0
        public static IRing <int> Part0(IRing <int> ring, IEnumerable <int> lengths, int iterations = 1)
        {
            var r = ring.Select(x => x).ToRing();

            var current     = 0;
            var skip        = 0;
            var lengthsList = lengths.ToList();

            foreach (var _ in Enumerable.Range(0, iterations))
            {
                foreach (var i in lengthsList)
                {
                    var range = Enumerable.Range(current, i).ToList();
                    var slice = range.ConvertAll(j => r[j]);
                    slice.Reverse();

                    var sidx = 0;

                    foreach (var j in range)
                    {
                        r[j] = slice[sidx++];
                    }
                    current += i + skip;
                    ++skip;
                }
            }

            return(r);
        }