Created
May 5, 2015 17:39
-
-
Save fabian57/7b059f297e8c0912b425 to your computer and use it in GitHub Desktop.
OH MON DIEU JE PENSAIS NE JAMAIS LE TROUVER!!!!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SIZE = 20 | |
cache = { (SIZE, SIZE): 0,} | |
def search(x, y): | |
if (x, y) not in cache: | |
if x == SIZE or y == SIZE: | |
return 1 | |
else: | |
cache[x+1, y] = search(x+1, y) | |
cache[x, y+1] = search(x, y+1) | |
return cache[x+1, y] + cache[x, y+1] | |
return cache[x, y] | |
print search(0,0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Je trouve ça un peu bizarre: normalement, le principe de la mémoïsation est de regarder si l'élément à calculer est déjà dans le cache, dans ce cas on le renvoie directement (ce que tu fais), mais sinon on le calcule, on le met dans le cache et on le renvoie: ce n'est pas ce que tu fais, puisque tu calcules et mets en cache d'autres éléments.