Safe cracker
Statement
Goal
An old safe has a dial lock with numbers 0 to 89. The dial may turn round and round in either direction. Being an old safe it will open within 3 numbers or closer in either direction to the KEY.Your task is to determine if the safe opens or remains shut and output the opening number.
Example:
KEY 30
COMBINATION 0>80<50>100<5>14<20
start:
0, move clockwise by 80
80, move counter clockwise by 50
30, move clockwise by 100
40, move counter clockwise by 5
35, move clockwise by 14
49, move counter clockwise by 20
29
|30 - 29| <= 3 so the safe will OPEN
Output:
OPEN
29
Note: during the combination the safe stopped on the opening number but will not open as it is a safe and needs the full COMBINATION to open. Only the final result may open the safe.
Input
Line 1: KEY the number that will open the safe.
Line 2: COMBINATION A start number followed by a sequence of rotations either> clockwise by a number and/or < counter-clockwise by a number.
Line 2: COMBINATION A start number followed by a sequence of rotations either
Output
Line 1: OPEN or LOCKED
Line 2: The opening or locked number
Line 2: The opening or locked number
Constraints
0<=KEY<=89
1<=COMBINATION length<=250
rotations will be either > or <
0<=rotation number<=1000
1<=COMBINATION length<=250
rotations will be either > or <
0<=rotation number<=1000
Example
Input
30 0>80<50>100<5>14<20
Output
OPEN 29
Game modes
Fastest, Shortest
Test cases
Test
Input
30
0>80<50>100<5>14<20
Output
OPEN
29
Validator 1 Validator
Input
20
0>50<10>135<80>13
Output
OPEN
18
Zero start Test
Input
0
0>91<89
Output
OPEN
2
Validator 2 Validator
Input
0
0<89>90
Output
OPEN
1
Test 3 Test
Input
89
20>31<30>80<15>18
Output
LOCKED
14
Validator 3 Validator
Input
88
31>40<32>45<80
Output
LOCKED
4
Test 4 Test
Input
24
89>2<100>88<2>30
Output
LOCKED
17
Validator 4 Validator
Input
33
0>2<20>40<20>40<2>16
Output
LOCKED
56
Limit Test
Input
10
89>39<29>1000<30
Output
LOCKED
79
Validator 5 Validator
Input
10
10>1000<9>1<100>8
Output
OPEN
10
One turn Test
Input
15
2<118
Output
LOCKED
64
Validator 6 Validator
Input
7
0>98
Output
OPEN
8
Uncrackable Test
Input
40
1>2>3<2<1>4>6>8>100<12<1>3<1000>99<1>999<1>1000>3<22>22
Output
OPEN
40
Validator 7 Validator
Input
70
1>2>3<2<1>4>6>8>100<12<1>3<1000>99<1>999<1>1000>3<22
Output
LOCKED
18
Around zero Test
Input
0
0<5>8<3>9<12
Output
OPEN
87
Validator 8 Validator
Input
0
0<3>5<1
Output
OPEN
1
High KEY Test
Input
88
3<20>40<22
Output
OPEN
1
Validator 9 Validator
Input
87
3<20>40<23
Output
OPEN
0
Solution language
Solution
Stub generator input