
def print_board(board):

    s = "*"
    for i in range(len(board[0])-1):
        s += str(i%10) + "|"
    s += str((len(board[0])-1)%10)
    s += "*\n"

    for i in range(len(board)):
        s += str(i%10)
        for j in range(len(board[0])-1):
            s += str(board[i][j]) + "|"
        s += str(board[i][len(board[0])-1])

        s += "*\n"
    s += (len(board[0])*2 + 1)*"*"

    print(s)


def make_empty_board(sz):
    board = []
    for i in range(sz):
        board.append([" "]*sz)
    return board




def put_seq_on_board(board, y, x, d_y, d_x, length, col):
    for i in range(length):
        board[y][x] = col
        y += d_y
        x += d_x


def sq_in_board(board, y, x):
    if y >= len(board):
        return False
    if x >= len(board):
        return False
    if x < 0:
        return False
    if y < 0:
        return False

    return True


def is_sequence_complete(board, col, y_start, x_start, length, d_y, d_x):
    if sq_in_board(board, y_start - d_y, x_start - d_x):
        if board[y_start-d_y][x_start-d_x] == col:
            return False

    if sq_in_board(board, y_start + length * d_y, x_start + length * d_x):
        if board[y_start + length * d_y][x_start + length * d_x] == col:
            return False

    for i in range(length):
        if board[y_start+i*d_y][x_start+i*d_x] != col:
            return False

    return True



if __name__ == '__main__':
    board = make_empty_board(8)
    put_seq_on_board(board, 1, 2, 1, 1, 3, "b")
    print_board(board)
    print(is_sequence_complete(board, "b", 1, 2, 3, 1, 1))
    print(is_sequence_complete(board, "b", 1, 2, 4, 1, 1))
    print(is_sequence_complete(board, "b", 1, 2, 2, 1, 1))

#################################################################################################


def print_lol_lines():
    f = open("data2.txt")
    lines = f.readlines()
    f.close()
    for line in lines:
        if "lol" in line.lower():
            #the end = "" is to avoid double-spaced output: line already
            #has a newline at its end, so we don't want print to add
            #another newline
            print(line, end = "")


def dict_to_str(d):
    str_d = ''
    for key, value in d.items():
        #We add the newline at the beginning so that the last line
        #won't have the newline appended, as required by the handout
        if str_d != '':
            str_d += '\n'
        #idea: convert the keys and values to strings, then add them
        #to str_d
        str_d += str(key) + ', ' + str(value)
    return str_d


def dict_to_str_sorted(d):
    #The same thing as dict_to_str, but we need to sort by key

    str_d = ''
    for key in sorted(d.keys()):
        value = d[key]
        if str_d != '':
            str_d += '\n'
        #idea: convert the keys and values to strings, then add them
        #to str_d
        str_d += str(key) + ', ' + str(value)
    return str_d

#####################################################

def print_lol_lines():
    f = open("data2.txt")
    lines = f.readlines()
    f.close()
    for line in lines:
        if "lol" in line.lower():
            #the end = "" is to avoid double-spaced output: line already
            #has a newline at its end, so we don't want print to add
            #another newline
            print(line, end = "")


def dict_to_str(d):
    str_d = ''
    for key, value in d.items():
        #We add the newline at the beginning so that the last line
        #won't have the newline appended, as required by the handout
        if str_d != '':
            str_d += '\n'
        #idea: convert the keys and values to strings, then add them
        #to str_d
        str_d += str(key) + ', ' + str(value)
    return str_d


def dict_to_str_sorted(d):
    #The same thing as dict_to_str, but we need to sort by key

    str_d = ''
    for key in sorted(d.keys()):
        value = d[key]
        if str_d != '':
            str_d += '\n'
        #idea: convert the keys and values to strings, then add them
        #to str_d
        str_d += str(key) + ', ' + str(value)
    return str_d