//should be private, but made public for tests public bool WorksFor(BookCollection bookCollection) { if (bookCollection.IsEmpty()) return false; //e.g. a book collection fitting this profile: 1;2;3;3;4;4;5;5 //when grouped by GroupBooks, we would have two groups: // first group: 1-book-per-title (2 items: (1) ; (2)) // second group: 2-books-per-title (3 items: (3;3) ; (4;4) ; (5;5)) var bookSets = GroupBooks(bookCollection); bool exactlyTwoQuantitiesOfBooksRemain = bookSets.Count() == 2; bool theSmallerGroupingContainsBooksSpanningTwoTitles = bookSets.First().Count() == 2; bool theSmallerGroupingContainsOneBookPerTitle = bookSets.First().Key == 1; bool theLargerGroupingContainsBooksSpanningThreeTitles = bookSets.Last().Count() == 3; bool theLargerGroupingContainsTwoBooksPerTitle = bookSets.Last().Key == 2; return exactlyTwoQuantitiesOfBooksRemain && theSmallerGroupingContainsBooksSpanningTwoTitles && theSmallerGroupingContainsOneBookPerTitle && theLargerGroupingContainsBooksSpanningThreeTitles && theLargerGroupingContainsTwoBooksPerTitle; }