Problem p03262 (python)

Fixed submission:

import numpy as np
import fractions

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    if N > 1:
        l = None
        for i, n in enumerate(x):
            if i == 0:
                l = n
            else:
                l = fractions.gcd(l, n)
        print(l)
    else:
        print(x[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

import numpy as np
import math

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    if N > 1:
        l = None
        for i, n in enumerate(x):
            if i == 0:
                l = n
            else:
                l = math.gcd(l, n)
        print(l)
    else:
        print(x[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

import numpy as np
import math

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    if N > 1:
        d = np.absolute(x[:N-1] - x[1:N])
        l = None
        for i, n in enumerate(d):
            if i == 0:
                l = n
            else:
                l = math.gcd(l, n)
        print(l)
    else:
        print(x[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

import numpy as np
import math

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    if N > 1:
        d = np.absolute(x[:N-1] - x[1:N])
        l = None
        for i, n in enumerate(d):
            if i == 0:
                l = n
            else:
                l = math.gcd(l, n)
        print(l)
    else:
        print(x[0])


if __name__ == '__main__':
    main()))

Buggy submission (verdict: Runtime Error):

import numpy as np
import math

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    if N > 1:
        d = x[:N-1] - x[1:N]
        l = None
        for i, n in enumerate(d):
            if i == 0:
                l = n
            else:
                l = math.gcd(l, n)
        print(l)
    else:
        print(x[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

import numpy as np
import math

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    if N > 1:
        d = []
        for i in range(x.size-2):
            d.append(x[i+1] - x[i])
        d = list(map(abs, list(set(d))))
        print(mygcd(d))
    else:
        print(x[0])

def mygcd(seq):
    if len(seq) == 1:
        return seq[0]
    else:
        a = seq.pop()
        b = seq.pop()
        return mygcd(seq.append(math.gcd(a, b)))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

import numpy as np

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    if N > 1:
        d = []
        for i in range(x.size-2):
            d.append(x[i+1] - x[i])
        d = np.absolute(np.asarray(list(set(d))))
    else:
        d = x
    m = np.min(d)

    for n in range(m, 0, -1):
        if d[d%n != 0].size == 0:
            print(n)
            return 0

if __name__ == '__main__':
    main()