Back
Close

Linear Sequence

Statement

 Goal

Information of 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/)

You can find the formula of the nth term of the sequence by this formula:
formula of the nth term = first term of the sequence + (n - 1) * common difference
(There's a quicker way to do it :) )

Task:
You will be given four integers on separated lines. If the four integers have the same difference, it is a linear sequence. For example, (2, 4, 6, 8) is a linear sequence as they have the common difference of 2

You will need to find the formula to find the nth term of the sequence, in the form of (bn+c). The nth term is 1-indexed, i.e. the indexes of the first four terms are 1, 2, 3, 4.

In this task, b and c will not be zero. For example, there will be no 4n+0 or 0n+8. However, b can be -1 or 1 so you will need to simplify the formula to -n and n respectively (not -1n or 1n).

A little conclusion about what I mentioned in the last paragraph, c can be any integer, positive or negative:
1n+c => n+c
-1n+c => -n+c

Notes: If the numbers provided are not a linear sequence, output ERROR
Input
a, b, c and d: integers, each on a separate line.
Output
Line 1: Output a formula in the form of bn+c or ERROR
Constraints
-100 < a, b, c and d < 5201315
b and c are always integers.
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 b and c are positive. Test
Input
32 43 54 65
Output
11n+21

Validator 2 Validator
Input
35 40 45 50
Output
5n+30

b is negative Test
Input
65 50 35 20
Output
-15n+80

Validator 3 Validator
Input
32 28 24 20
Output
-4n+36

c is negative Test
Input
-8 -4 0 4
Output
4n-12

Validator 4 Validator
Input
-9 -5 -1 3
Output
4n-13

both b and c are negative Test
Input
-9 -10 -11 -12
Output
-n-8

Validator 5 Validator
Input
-32 -38 -44 -50
Output
-6n-26

b is 1 Test
Input
10 11 12 13
Output
n+9

Validator 6 Validator
Input
3 4 5 6
Output
n+2

b 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