import random
from brain_games.engine import run_game


def play():
    RULE = "What number is missing in the progression?"
    run_game(RULE, generate_data)


def generate_data():
    a1 = random.randrange(20)
    # a1 is the first number of arithmetic progression
    d = random.randint(2, 9)
    # d is the differance of successive members
    missing_position = random.randrange(10)
    arith_sequence = [str(a1)]
    for i in range(1, 10):
        arith_sequence.append(str(a1 + i * d))
    correct_answer = arith_sequence[missing_position]
    arith_sequence.remove(correct_answer)
    arith_sequence.insert(missing_position, '..')
    expression = ' '.join(arith_sequence)
    return expression, str(correct_answer)
