Here's another freebie, but I am not really sure how to solve it. Guess I wouldn't be getting that job at Google :)
This problem was asked by Google.
The area of a circle is defined as πr^2. Estimate π to 3 decimal places using a Monte Carlo method.
Hint: The basic equation of a circle is x2 + y2 = r2.
c++ solution
@Absinthe Even worse overengineering than previously: https://gitlab.com/tymorl/warmups/blob/master/MCPie/sol.cpp .
I think the most interesting part is the stopping condition. I arrived at it by a mix of trial-and-error and intuition. The intuition was just "the square is needed, because something something statistics", so pretty bad. If anyone knows what the stopping condition should be I am all ears.
c++ solution
@Absinthe Both of these are not EnterpriseSolutions™ and I like keeping my code EnterpriseGrade™, especially when writing c++. The first one would require giving Point access to dis and gen, which is hard to do without making them global variables or something and the latter... well, if something is a test it should return a boolean.
More seriously, yours are good suggestions for writing #toyprogrammingchallenge solutions in general, but if I wanted to do that I wouldn't make any classes at all, just a couple functions.