Strange limiting value for longest path problem While I was trying to solve this longest path problem for a directed cyclic graph I posted days ago Longest chain of n-digit square numbers where last digit equals first digit of next, I thought about resolving a simpler problem, i.e. to find an upper bound value for how many squares with n digits are contained in the longest chain, and this function seems to do the job:
1 + m_1 + m_4 + m_5 + m_6 + m_9,  where m_i = min(#d-digit squares ending in i, #d-digit squares starting with i).
Trying with various values something "strange" came out: if you divide the number of squares with n digits for that upper bound function and square it, the result will be very near to π. It's a bit lower then π, so maybe with the right value of the arrangement, π could be the limit of that succession. Could that have some heuristic explanation? Or it's just a succession with another limiting value?
For n = 12, number of squares = 683772, upper bound function = 386508, (683772/386508)^2 = 3.129721192
For higher n, the algorithm slows down alot
Thanks
 A: Let's find the limiting value. I will look at all the perfect squares between $10^n$ and $10^{n+1}$ for some large $n$; technically these are $(n+1)$-digit squares, but that won't matter for the limit.
The total number of perfect squares in this range is roughly $10^{(n+1)/2} - 10^{n/2} = (\sqrt{10}-1) \cdot 10^{n/2}$. (You didn't give this quantity a name, so let's call it $m$.)
For the number of perfect squares starting with a digit $d$, we want the prefect square to be between $d \cdot 10^n$ and $(d+1) \cdot 10^n$, so the number being squared is between $\sqrt d \cdot 10^{n/2}$ and $\sqrt{d+1} \cdot 10^{n/2}$. Therefore the fraction of the perfect squares that are in this range is $\frac{\sqrt{d+1} - \sqrt d}{\sqrt{10} - 1}$ in the limit. (It will quickly get close to this number; the only source of error is that the bounds $\sqrt d \cdot 10^{n/2}$ and $\sqrt{d+1} \cdot 10^{n/2}$ are not integers.)
For the number of perfect squares that end in a digit $d$, we look at the last digit of the number being squared: if it ends in $0, 1, 2, 3, 4, 5, 6, 7, 8, 9$ then the square ends in $0, 1, 4, 9, 6, 5, 6, 9, 4, 1$. So we see $1, 4, 9, 6$ each $\frac15$ of the time, but $5$ only $\frac1{10}$ of the time.
In fact, the value $\frac{\sqrt{d+1} - \sqrt d}{\sqrt{10} - 1}$ is never as large as $\frac15$ and for $d=5$ it is smaller than $\frac1{10}$, too. So the number of squares starting with a digit is always the bottleneck. We use the formula $\frac{\sqrt{d+1} - \sqrt d}{\sqrt{10} - 1}$ to estimate $\frac{m_d}{m}$ for $d = 1, 4, 5, 6, 9$; the sum $\frac{m_1 + m_4 + m_5 + m_6 + m_9}{m}$ is (for large $n$) about
$$
   \frac{(\sqrt 2 -\sqrt1) + (\sqrt 5 - \sqrt 4)+(\sqrt 6-\sqrt5) + (\sqrt7 - \sqrt 6) + (\sqrt{10}-\sqrt 9)}{\sqrt{10} - 1}
$$
which simplifies to
$$
   \frac{\sqrt{10} + \sqrt7 + \sqrt2 - 6}{\sqrt{10} - 1}.
$$
You are actually taking the reciprocal $\frac{m}{m_1+m_4+m_5+m_6+m_9}$ and then squaring it (I am dropping the $1+$ in your function, since it will not affect the limit). So the quantity close to $\pi$ that you are observing is
$$
   \left(\frac{m}{m_1+m_4+m_5+m_6+m_9}\right)^2 = \frac{(\sqrt{10}-1)^2}{(\sqrt{10} + \sqrt7 + \sqrt2 - 6)^2} \approx 3.129739109\dots
$$
