title: Project Euler #15 in Python
body: <p>I am newbie in Python. I'm stuck on doing Problem 15 in Project-Euler in reasonable time. The problem in memoize func. Without memoize all working good, but only for small grids. I've tried to use Memoization, but result of such code is "1" for All grids.</p>
  
  <pre><code>def memoize(f): #memoization
      memo = {}
  
      def helper(x):
          if x not in memo:
              memo[x] = f(x)
          return memo[x]
      return helper
  
  
  @memoize
  def search(node):
      global route
      if node[0] &gt;= k and node[1] &gt;= k:
          route += 1
          return route
      else:
          if node[0] &lt; k + 1 and node[1] &lt; k + 1:
              search((node[0] + 1, node[1]))
              search((node[0], node[1] + 1))
      return route
  
  
  k = 2 #grid size
  route = 0
  print(search((0, 0)))
  </code></pre>
  
  <p>If commenting out code to disable memoize func:</p>
  
  <pre><code>#@memoize
  </code></pre>
  
  <p>all works, but to slow for big grids. What am i doing wrong? Help to debbug. Thx a lot!</p>
  
  <p><strong>Update1:</strong> </p>
  
  <p>Thank for your help, I've found answer too:</p>
  
  <pre><code>def memoize(f):
      memo = {}
  
      def helper(x):
          if x not in memo:
              memo[x] = f(x)
          return memo[x]
      return helper
  
  
  @memoize
  def search(node):
      n = 0
      if node[0] == k and node[1] == k:
          return 1
      if node[0] &lt; k+1 and node[1] &lt; k+1:
          n += search((node[0] + 1, node[1]))
          n += search((node[0], node[1] + 1))
      return n
  
  k = 20
  print(search((0, 0)))
  </code></pre>
  
  <p>Problem was not in memoize func as i thought before. Problem was in 'search' function. Whithout globals it wroiking right i wished. Thx for comments, they was really usefull.</p>