Tag Archives: sets

Find two sets where the median of one is the mean of the other and vice versa in C#

For an upcoming book, I wanted to find sets where the mean (average) of one is the median (middle value) of the other and vice versa. I wanted to avoid trivial examples such as {1, 1, 1} and where the … Continue reading

Posted in algorithms, combinatorics | Tagged , , , , , , , , , , | Leave a comment

Perform set operations on enumerable lists in C#

To demonstrate set operations, this example creates two lists of Person objects. The Person class implements IEquatable. The code then uses the following code to display the lists and their intersection, union, difference, and exclusive or (xor). // Display the … Continue reading

Posted in mathematics | Tagged , , , , , , , , , , , , | Leave a comment

Use set operators in C#

This example shows how you can add set operators to make working with sets slightly easier. The example Perform set operations in C# explains how to use the HashSet class to represent and manipulate sets. Unfortunately to manipulate the sets … Continue reading

Posted in algorithms, classes, mathematics | Tagged , , , , , , , , , , , , , , , , | Leave a comment

Perform set operations in C#

The HashSet class can represent objects in a set and perform set operations such as finding the union or intersection of two sets. When the program starts, the following code builds two sets and performs some operations with them. // … Continue reading

Posted in algorithms, classes, mathematics | Tagged , , , , , , , , , , , | 2 Comments