Skip to content

Instantly share code, notes, and snippets.

@abolibibelot
Created May 6, 2013 20:47
Show Gist options
  • Save abolibibelot/5528071 to your computer and use it in GitHub Desktop.
Save abolibibelot/5528071 to your computer and use it in GitHub Desktop.
Constraints 2
void Main()
{
var chrono = new Stopwatch();
chrono.Start();
Syntouze res = null;
for (var i=0; i < 1000; i++)
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 touze = new Syntouze{Taz=taz,Pieds=pieds,Gifles=gifles}
where touze.Bugs <= 50
select touze)
.Max();
chrono.ElapsedMilliseconds.Dump();
res.Dump();
}
class Syntouze : IComparable
{
public int Taz{get;set;}
public int Pieds{get;set;}
public int Gifles{get;set;}
public int Bugs{get {return Gifles * 2 + Pieds * 5 + Taz * 11;}}
public int Productivite{get{return Gifles * 50 + Pieds * 100 + Taz * 200;}}
public int CompareTo(object o)
{
return Productivite - ((Syntouze)o).Productivite;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment