Project Euler 826 - Birds on a Wire

Official link: https://projecteuler.net/problem=826

Note: I don't care much for statistics problems and managed to brute forced the solution!

Thought Process

First thing I did, which I always do for these types of problems, is to create a Monte-Carlo simulation to get an approximate answer. At first I couldn't tell much except for the fact that as n increases F(n) decreases slowly, of course given the nature of the problem I expect that it will converge to some value and hence I did a bunch of trials for a large amount of birds

The trial size goes down so the accuracy is affected but from this I conjectured that F(n) goes towards 0.38888.... which WolframAlpha told me is 7/18.

Given the relative simplicity of this fraction I again conjectured 2 things:

To test this I used the fractions module limit_denominator() method which given a decimal, will approximate it as a fraction with a given denominator size.

Firstly, I got an approximate value for all values n = 4 to 7, using 10,000,000 trials, then again using 100,000,000 trials and tested the fraction I got when I limited the denominator to 100 and 1,000. I show my results below:

Using this it is clear that F(7) = 4/9, now using my conjectured point 2, and F(3) = 1/2, I can calculate a = 15, b = 18.

Then, to my amazement using F(n) = (7n + 15)/(18n + 18) I get F(5) = 25/54, F(6) = 19/42, exactly as I guessed!

Being pretty sure this was the correct closed form for F(n), I just ran my code for all primes less than a million and voila!

Interactive Code

No interactive code for this problem, instead I provide my Monte-Carlo simulation function