Find all paths in Python (project Euler Problem 15)

preview_player
Показать описание
This was a fun problem and eventual solution is 5 lines long so no code attached!

SOCIAL:

WEBSITES:

-~-~~-~~~-~~-~-
Latest and Best Arduino Playlist in Collaboratio with DFRobot:
-~-~~-~~~-~~-~-
Рекомендации по теме
Комментарии
Автор

More generally... There are 40 "unit steps" needed to get from the upper left corner to the lower right. You can choose which twenty of these are in the rightward direction, so the answer is (in the usual way of describing such things), 40 choose 20. Note that this solution is more general than the one given in the video, which only works for square grids. If the grid was 20x10, then the answer would be 30 choose 10. Alternatively, you could use 30 choose (30-10=20), which is the same value. The general formula for n choose r (where n is the total number of steps and r is the number of steps to be chosen) is n!/(r![n-r!]). If you want to avoid having the factorial blow up quite so quickly, you can compute this by alternately multiplying by a factor in the numerator and dividing by a factor in the denominator. This works because in any sequence of consecutive natural numbers of length m, there is always one number that is divisible by m.

bobbun
Автор

import math
def central_binomals(n):
return
print(central_binomals(20))

Adam-yfux
Автор

Hi! I find your method fascinating, as it allows us to actually see all the possible paths. I tried inputting your code at the 3:28 mark, however, I get the "Expected int as r" error message. I've been trying to fix it for the last few hours, any idea why? Thank you!

Robotboy
Автор

3 years ago, but still works
Thaks man!

vovaherchuk
Автор

Euler is pronounced "oil er" :) cheers!

Daniel-ngfi
Автор

thats like find how many different moves you can make on chess :) its great

rafaelmarroquin
Автор

Hi I am doing a research on python ; I have my adjacency matrix it collects 12 cities and I would love to write a programm on python that give the Hamiltonian Cycle . Can any body help !

bouaakilikram