Problem p03262 (python)

Fixed submission:
def gcd(a, b):
  if(a == b):
    return a
  elif(a % b == 0):
    return b
  elif(b % a == 0):
    return a
  elif(a == 1 or b == 1):
    return 1
  elif(a > b):
    return gcd(a- a// b* b, b)
  elif(a < b):
    return gcd(a, b- b// a* a)

def ggcd(lista):
  if(len(lista) == 1):
    return lista.pop()
  else:
    l = lista.pop()
    for i in range(1, len(lista)):
      l = gcd(l, lista.pop())
    return l

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
d = []
gcds = set()
x.sort()

for i in range(N):
  d.append(x[i+ 1]- x[i])

gcds.add(d[0])

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.add(d[i+ 1])

print(ggcd(gcds))

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
  if(a == b):
    return a
  elif(a > b):
    return gcd(a- b, b)
  elif(a < b):
    return gcd(a, b- a)
          

def ggcd(lista):
  if(len(lista) == 1):
    return lista.pop()
  else:
    l = lista.pop()
    for i in range(1, len(lista)):
      l = gcd(l, lista.pop())
    return l

N, X = map(int, input().split())
x = list(map(int, input().split()))
m = min(x)
d = []
gcds = set()
if(X < m):
  d.append(m- X)
else:
  if(N > 1):
    x.sort()
    if(x[1] > X):
      d.append(X- m)
      del x[0]
      x.insert(0, X)
    else:
      d.append(x[1]- x[0])
      del x[0]
      x.insert(0, X)
  else:
    d.append(abs(x[0]- X))
  
x.sort()
  
for i in range(N- 1):
  d.append(x[i+ 1]- x[i])
  
gcds.add(d[0])

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.add(d[i+ 1])

print(ggcd(gcds))

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
  if(a == b):
    return a
  elif(a > b):
    return gcd(a- b, b)
  elif(a < b):
    return gcd(a, b- a)
          

def ggcd(lista):
  if(len(lista) == 1):
    return lista.pop()
  else:
    l = lista.pop()
    for i in range(1, len(lista)):
      l = gcd(l, lista.pop())
    return l

N, X = map(int, input().split())
x = list(map(int, input().split()))
m = min(x)
d = []
gcds = set()
if(X < m):
  d.append(m- X)
else:
  if(N > 1):
    x.sort()
    if(x[1] > X):
      d.append(X- m)
      del x[0]
      x.insert(0, X)
    else:
      d.append(x[1]- x[0])
      del x[0]
      x.insert(0, X)
  
x.sort()
  
for i in range(N- 1):
  d.append(x[i+ 1]- x[i])
  
gcds.add(d[0])

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.add(d[i+ 1])

print(ggcd(gcds))

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
  if(a == b):
    return a
  elif(a > b):
    return gcd(a- b, b)
  elif(a < b):
    return gcd(a, b- a)
          

def ggcd(lista):
  if(len(lista) == 1):
    return lista.pop()
  else:
    l = lista.pop()
    for i in range(1, len(lista)):
      l = gcd(l, lista.pop())
    return l

N, X = map(int, input().split())
x = list(map(int, input().split()))
d = []
gcds = set({abs(X- x[0])})
x.sort()

for i in range(N- 1):
  d.append(x[i+ 1]- x[i])
  
d.append(abs(X- x[0]))

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.add(d[i+ 1])

print(ggcd(gcds))

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
  if(a == b):
    return a
  elif(a > b):
    return gcd(a- b, b)
  elif(a < b):
    return gcd(a, b- a)
          

def ggcd(lista):
  if(len(lista) == 1):
    return lista.pop()
  else:
    l = lista.pop()
    for i in range(1, len(lista)):
      l = gcd(l, lista.pop())
    return l

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
d = []
gcds = set()
x.sort()

for i in range(N):
  d.append(x[i+ 1]- x[i])
  
gcds.add(d[0])

for i in range(N- 1):
  if(d[i+ 1] != d[i]):
    gcds.add(d[i+ 1])

print(ggcd(gcds))