Skip to content

Instantly share code, notes, and snippets.

@cbadke
Created December 5, 2012 14:56
Show Gist options
  • Save cbadke/4216117 to your computer and use it in GitHub Desktop.
Save cbadke/4216117 to your computer and use it in GitHub Desktop.
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