title: Euclidean algorithm (GCD) with multiple numbers?
body: <p>So I'm writing a program in Python to get the GCD of any amount of numbers.</p>
  
  <pre><code>def GCD(numbers):
  
      if numbers[-1] == 0:
          return numbers[0]
  
  
      # i'm stuck here, this is wrong
      for i in range(len(numbers)-1):
          print GCD([numbers[i+1], numbers[i] % numbers[i+1]])
  
  
  print GCD(30, 40, 36)
  </code></pre>
  
  <p>The function takes a list of numbers. 
  This should print 2. However, I don't understand how to use the the algorithm recursively so it can handle multiple numbers. Can someone explain? </p>
  
  <p>updated, still not working:</p>
  
  <pre><code>def GCD(numbers):
  
      if numbers[-1] == 0:
          return numbers[0]
  
      gcd = 0
  
      for i in range(len(numbers)):
          gcd = GCD([numbers[i+1], numbers[i] % numbers[i+1]])
          gcdtemp = GCD([gcd, numbers[i+2]])
          gcd = gcdtemp
  
      return gcd
  </code></pre>
  
  <hr>
  
  <p>Ok, solved it</p>
  
  <pre><code>def GCD(a, b):
  
      if b == 0:
          return a
      else:
          return GCD(b, a % b)
  </code></pre>
  
  <p>and then use reduce, like</p>
  
  <pre><code>reduce(GCD, (30, 40, 36))
  </code></pre>