Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 13, 2016 15:38
Show Gist options
  • Save Fhernd/0eb8eb1ef0d96931c3e888337f963e37 to your computer and use it in GitHub Desktop.
Save Fhernd/0eb8eb1ef0d96931c3e888337f963e37 to your computer and use it in GitHub Desktop.
General approach to find the smaller and larger values from multiple sequences. [OrtizOL]
// Sequences of bid values:
List<int> bidValues1 = new List<int>() { 1, 2, 3, 4, 5 };
List<int> bidValues2 = new List<int>() { 5, 3, 4, 1, 2 };
List<int> bidValues3 = new List<int>() { 4, 5, 2, 3, 5 };
List<int> bidValues4 = new List<int>() { 3, 3, 0, 2, 3 };
// Add all four collections to a new list:
List<List<int>> bidValues = new List<List<int>>();
bidValues.Add(bidValues1);
bidValues.Add(bidValues2);
bidValues.Add(bidValues3);
bidValues.Add(bidValues4);
// Uses Aggregate extension method to compare all four sequences:
bidValues.Aggregate((bids1, bids2) =>
bids1.Zip(bids2, (bid1, bid2) => Math.Max(bid1, bid2)).ToList())
.Dump("Maximum Bids (General Approach)");
bidValues.Aggregate((bids1, bids2) =>
bids1.Zip(bids2, (bid1, bid2) => Math.Min(bid1, bid2)).ToList())
.Dump("Minimum Bids (General Approach)");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment