I decided to try and implement (a version of) the simulated annealing algorithm using just LINQ, just to see if I could.
I'd love it if anybody could see any ways to improve it, or give advice on any cool tricks for doing this kind of thing.
var result = (from res in Enumerable.Range(0, 1)
let R = new Random()
let initial = Enumerable.Range(0, 10).Select(i => R.Next(-10, 10))
let iterations = Enumerable.Range(0, 100)
let Schedule = (Func<int, float>)
(X => 4 + (float)Math.Sin(X))
from iteration in iterations
let temperature = Schedule(iteration)
let state = Enumerable.Range(0, 10).Select(i => R.Next(-10, 10))
let DeltaE = state.Sum() - initial.Sum()
where DeltaE > 0 ||
Math.Pow(Math.E, DeltaE / temperature) > R.NextDouble()
select state.ToList()
).OrderBy(S => S.Sum()).First();
Any input is appreciated :)