unlucky_1

We’ll say that a 1 immediately followed by a 3 in a list is an “unlucky” 1. Return true if the given list contains an unlucky 1 in the first 2 or last 2 positions in the list.

This exercise was taken from codingbat.com and has been adapted for the Python language. There are many great programming exercises there, but the majority are created for Java.

Test 1

Input:

[1, 3, 4, 5]

Output:

True

Test 2

Input:

[2, 1, 3, 4, 5]

Output:

True

Test 3

Input:

[1, 1, 1]

Output:

False

Test 4

Input:

[1, 3, 1]

Output:

True

Test 5

Input:

[1, 1, 3]

Output:

True

Test 6

Input:

[1, 2, 3]

Output:

False

Test 7

Input:

[3, 3, 3]

Output:

False

Test 8

Input:

[1, 3]

Output:

True

Test 9

Input:

[1, 4]

Output:

False

Test 10

Input:

[1]

Output:

False

Test 11

Input:

[]

Output:

False

Test 12

Input:

[1, 1, 1, 3, 1]

Output:

False

Test 13

Input:

[1, 1, 3, 1, 1]

Output:

True

Test 14

Input:

[1, 1, 1, 1, 3]

Output:

True

Test 15

Input:

[1, 4, 1, 5]

Output:

False

Test 16

Input:

[1, 1, 2, 3]

Output:

False

Test 17

Input:

[2, 3, 2, 1]

Output:

False

Test 18

Input:

[2, 3, 1, 3]

Output:

True

Test 19

Input:

[1, 2, 3, 4, 1, 3]

Output:

True