Skip to main content
1 of 3
mmumboss
  • 580
  • 2
  • 7

MATLAB

This is a tough one. Since we do not really know the question, the only viable method of getting the answer is by means of a global optimisation method. In this case I opted for the simulated annealing method, since this one has given me nice answers to tough questions before.

All this code is doing is looking for the optimal value of a function which input is life itself! And the amazing thing is that it works. So, did I just validate Deep Thought?

tic;

answer=round(simulannealbnd(@(life)abs(3.7376696-log(life)),140489, ...
             -inf,inf,saoptimset('MaxFunEvals',10^16)));
toc;

Output:

answer =

    42

Elapsed time is 74.892428 seconds.
mmumboss
  • 580
  • 2
  • 7