Create a function that will return true if all numbers in the sequence follow the same counting pattern. If the sequence of numbers does not follow the same pattern, the function should return false.

Sequences will be presented in an array of varied length. Each array will have a minimum of 3 numbers in it.

The sequences are all simple and will not step up in varying increments such as a Fibonacci sequence.

JavaScript examples:

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

Starter code: def validate_sequence(sequence):
	

Solutions:
def validate_sequence(seq):
	return len({a - b for (a, b) in zip(seq, seq[1:])}) == 1


def validate_sequence(sequence):
	return sequence == list(range(sequence[0], sequence[-1] + 1, sequence[1] - sequence[0]))


def validate_sequence(s):
	return sum(s) == (s[0] + s[-1]) * len(s) / 2


def validate_sequence(sequence):
	print(sequence)
	d = sequence[1] - sequence[0]
	for i in range(2, len(sequence)):
		if sequence[i] - sequence[i - 1] != d:
			return False
	return True


def validate_sequence(sequence):
	step = sequence[1] - sequence[0]
	return all((b - a == step for (a, b) in zip(sequence, sequence[1:])))


def validate_sequence(sequence):
	return len(set([n - p for (p, n) in zip(sequence, sequence[1:])])) == 1


validate_sequence = lambda a: eval('=='.join([str(x) for x in [a[i] - a[i + 1] for i in range(len(a) - 1)]]))


def validate_sequence(sequence):
	increment = sequence[1] - sequence[0]
	return all((y - x == increment for (x, y) in zip(sequence, sequence[1:])))


def validate_sequence(sequence):
	i = sequence[1] - sequence[0]
	l = list(range(min(sequence), max(sequence) + 1, i))
	return l == sequence


def validate_sequence(seq):
	diff = seq[1] - seq[0]
	for (i, n) in enumerate(seq[:-1]):
		if seq[i + 1] - n != diff:
			return False
	return True