Created
December 5, 2012 14:56
-
-
Save cbadke/4216117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void descriptiveImp() | |
{ | |
var weatherData = File.ReadAllLines(@"C:\weather.dat"); | |
Func<string,DataPoint> ConvertLineToDataPoint = line => { | |
var currLine = line.Trim().Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); | |
return new DataPoint | |
{ | |
day = Int32.Parse(currLine[0]), | |
max = Int32.Parse(currLine[1]), | |
min = Int32.Parse(currLine[2]) | |
}; | |
}; | |
Func<DataPoint,Tuple<int,int>> ConvertDataPointToDaySpreadTuple = dp => new Tuple<int, int>(dp.day, dp.max - dp.min); | |
Func<Tuple<int, int>, Tuple<int, int>, Tuple<int, int>> TupleWithSmallestSpread = (a, b) => a.Item2 < b.Item2 ? a : b; | |
var minSpread = weatherData.Select(ConvertLineToDataPoint) | |
.Select(ConvertDataPointToDaySpreadTuple) | |
.Aggregate(TupleWithSmallestSpread); | |
Console.WriteLine("The day with the minimum spread is {0} and spread is {1}", minSpread.Item1, minSpread.Item2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment