Skip to content

Instantly share code, notes, and snippets.

@abolibibelot
Created May 6, 2013 20:28
Show Gist options
  • Save abolibibelot/5527922 to your computer and use it in GitHub Desktop.
Save abolibibelot/5527922 to your computer and use it in GitHub Desktop.
void Main()
{
var res = (from taz in new[]{0,1,2}
from pieds in Enumerable.Range(1,10 - taz)
from gifles in Enumerable.Range(1,10 - pieds - taz)
let productivite = gifles * 50 + pieds * 100 + taz * 200
let bugs = gifles * 2 + pieds * 5 + taz * 11
where bugs <= 50
select new []{taz,pieds,gifles,bugs,productivite})
.MaxOf(o => o[4]);
res.Dump();
}
// Define other methods and classes here
static class Ext
{
public static T MaxOf<T>(this IEnumerable<T> seq, Func<T,int> comp)
{
T res = default(T);
int max = int.MinValue;
foreach(var t in seq)
{
if (comp(t) > max)
{res = t; max = comp(t);}
}
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment