fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. var datesList = new List<DateTime>() {
  11. new DateTime(2013,1,1),new DateTime(2013,8,1),new DateTime(2013,10,1),
  12. new DateTime(2013,1,15),new DateTime(2013,1,22),new DateTime(2013,1,28),
  13. new DateTime(2013,2,10),new DateTime(2013,2,11),new DateTime(2013,2,22),
  14. };
  15. var abRotations = datesList
  16. .GroupBy(d => CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(d, CalendarWeekRule.FirstDay, DayOfWeek.Monday))
  17. .Select((wg, i) => new { WeekGroup = wg, Index = i })
  18. .GroupBy(x => x.Index % 2);
  19.  
  20. List<DateTime> A_Rotation = abRotations.First().SelectMany(x => x.WeekGroup).ToList();
  21. List<DateTime> B_Rotation = abRotations.Last().SelectMany(x => x.WeekGroup).ToList();
  22.  
  23. Console.WriteLine("A-Rotation weeks: " + A_Rotation.Count);
  24. foreach (DateTime aDate in A_Rotation)
  25. Console.WriteLine(aDate.ToString());
  26. Console.WriteLine("B-Rotation weeks: " + B_Rotation.Count);
  27. foreach (DateTime bDate in B_Rotation)
  28. Console.WriteLine(bDate.ToString());
  29.  
  30. }
  31. }
  32.  
  33.  
  34.  
Success #stdin #stdout 0.07s 34288KB
stdin
Standard input is empty
stdout
A-Rotation weeks: 5
1/1/2013 12:00:00 AM
10/1/2013 12:00:00 AM
1/22/2013 12:00:00 AM
2/10/2013 12:00:00 AM
2/22/2013 12:00:00 AM
B-Rotation weeks: 4
8/1/2013 12:00:00 AM
1/15/2013 12:00:00 AM
1/28/2013 12:00:00 AM
2/11/2013 12:00:00 AM