Linear Sequence
Statement
Goal
WHAT IS LINEAR SEQUENCE?A linear sequence is a number pattern that increases or decreases by the same amount each time. (From BBC Bitesize: https://www.bbc.co.uk/bitesize/guides/z7j2pv4/revision/)
The nth term can be found using the formula:
nth term = first term of the sequence + (n - 1) * common difference
--------------------------------------------------------------------------------------------------------------------
YOUR TASK
You will be given four integers, a, b, c and d, each representing the first, second, third and forth term of the sequence. You need to determine whether they are in a linear sequence.
If they are in a linear sequence, you need to find the formula to find the nth term of the sequence, in the form of x
In this task, x and y are non-zero. However, x can be
1n+y → n+y
-1n+y → -n+y
If the numbers provided are not a linear sequence, output
Input
Lines 1 to 4: a, b, c and d: integers, each on a separate line.
Output
Line 1: Output a formula in the form of xn+ y or xn- y or ERROR
Constraints
-100 < a, b, c and d < 5201315
x and y are always integers.
x, y ≠0
x and y are always integers.
x, y ≠0
Example
Input
15 20 25 30
Output
5n+10
Game modes
Fastest, Shortest, Reverse
Test cases
Example Test
Input
15
20
25
30
Output
5n+10
Validator 1 Validator
Input
10
19
28
37
Output
9n+1
Bigger Number, both x and y are positive. Test
Input
32
43
54
65
Output
11n+21
Validator 2 Validator
Input
35
40
45
50
Output
5n+30
x is negative Test
Input
65
50
35
20
Output
-15n+80
Validator 3 Validator
Input
32
28
24
20
Output
-4n+36
y is negative Test
Input
-8
-4
0
4
Output
4n-12
Validator 4 Validator
Input
-9
-5
-1
3
Output
4n-13
both x and y are negative Test
Input
-9
-13
-17
-21
Output
-4n-5
Validator 5 Validator
Input
-32
-38
-44
-50
Output
-6n-26
x is 1 Test
Input
10
11
12
13
Output
n+9
Validator 6 Validator
Input
3
4
5
6
Output
n+2
x is -1 Test
Input
6
5
4
3
Output
-n+7
Validator 7 Validator
Input
-9
-10
-11
-12
Output
-n-8
ERROR Test
Input
69
420
5201314
69
Output
ERROR
Validator 8 Validator
Input
8
9
5
6
Output
ERROR
Solution language
Solution
Stub generator input