We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Did not expect the major obstacle to be OverflowError from exponentiation of (sqrt(5)+1)/2. Horrible use of diagonalization without numpy.
EDIT: Learned the Decimal module, which helps in calculating very large decimal value. But got stuck with insufficient decimal.getcontext().prec as the value after exponentiation is very, very large (thousands? millions? or even more of digits), while I want every single digit to the left of the decimal point. I wonder if anything could be done to this intermediate step, as there is still crucial ahead before performing the final modulo opeartion. And the I obtained is also subject to significant error as it is found with np.linalg.eig(). Heck, there is even decimal.Overflow: above Emax!
EDIT 2: When I looked closely, unfortunately, this approach seems to start deviating from the results of the DP approach (which is slower but correct) for (763701899 vs 763701898). Using numpy without Decimal is even worse. When the input is 2000 3 then it is the embarrassing 973324784 vs nan vs 709134169.
EDIT 3: Stupid me to have thought about diagonalization. It's not the only option to achieve matrix exponentiation. Simple recursive divide and conquer like mergesort can do the job. And one more thing, construct your matrix according to .
Project Euler #114: Counting block combinations I
You are viewing a single comment's thread. Return to all comments →
Did not expect the major obstacle to be
OverflowError
from exponentiation of(sqrt(5)+1)/2
. Horrible use of diagonalization without numpy.EDIT: Learned the
Decimal
module, which helps in calculating very large decimal value. But got stuck with insufficientdecimal.getcontext().prec
as the value after exponentiation is very, very large (thousands? millions? or even more of digits), while I want every single digit to the left of the decimal point. I wonder if anything could be done to this intermediate step, as there is still crucial ahead before performing the final modulo opeartion. And the I obtained is also subject to significant error as it is found withnp.linalg.eig()
. Heck, there is evendecimal.Overflow: above Emax
!EDIT 2: When I looked closely, unfortunately, this approach seems to start deviating from the results of the DP approach (which is slower but correct) for (
763701899
vs763701898
). Usingnumpy
withoutDecimal
is even worse. When the input is2000 3
then it is the embarrassing973324784
vsnan
vs709134169
.EDIT 3: Stupid me to have thought about diagonalization. It's not the only option to achieve matrix exponentiation. Simple recursive divide and conquer like mergesort can do the job. And one more thing, construct your matrix according to .
Now perhaps I'm ready for Problem 109 Darts.