コード例 #1
0
ファイル: server.py プロジェクト: Liaoqitian/Exam-Generation
def generate(data):

    # Randomize the percentage of program which is serial. Store the information in params.
    p = [5, 10, 20, 25, 50, 100]
    idx = random.choice(range(6))
    percentage = p[idx]
    data['params']['percentage'] = percentage

    # Compute the corresponding solutions for each of the possible percentages. Determine the correct ones. Store the information in params.
    solutions = [100 / i for i in p]
    solution = solutions[idx]
    data['params']['solution'] = solution
    # Store the incorrect solutions in params. "i" is short-hand for incorrect.
    copy = []
    for i in range(6):
        copy.append(solutions[i])
    copy.remove(solution)
    i0 = copy[0]
    i1 = copy[1]
    i2 = copy[2]
    i3 = copy[3]
    i4 = copy[4]
    data['params']['i0'] = i0
    data['params']['i1'] = i1
    data['params']['i2'] = i2
    data['params']['i3'] = i3
    data['params']['i4'] = i4
コード例 #2
0
def removeLengths(start, poss_lengths, board):
    N = len(board)
    adj = getAdj(start[0], start[1], False, N)
    copy = poss_lengths[0:]
    for length in poss_lengths:
        for i in adj:
            if board[i[0]][i[1]] == length and length != 1:
                copy.remove(length)
                break
    return copy
コード例 #3
0
def getAdj(xloc, yloc, do_shuffle, N):
    adj = []
    adj.append((xloc+1, yloc))
    adj.append((xloc-1, yloc))
    adj.append((xloc, yloc+1))
    adj.append((xloc, yloc-1))
    copy = adj[0:]
    for i in adj:
        if (i[0] < 0 or i[0] > (N-1)) or (i[1] < 0 or i[1] > (N-1)):
            copy.remove(i)
    if do_shuffle:
        copy = shuffle(copy)
    return copy
コード例 #4
0
def checkWord(word, hand):
    """
    Checks each character in a word against a list of characters ('hand').
    Each character in the hand can only be used once so it is removed
    after being checked.
    Returns false if there is not a unique character in 'hand' for every
    character in 'word'.
    """
    copy = hand[:]
    for c in word:
        if c in copy:
            copy.remove(c)
        else:
            return False
    return True
コード例 #5
0
def remove_cycles(path_list):
    """
     It removes from path_list the set of paths that include some cycles in their path.
     Format of the parameter is:
        Args:
            path_list (LIST of Path Class): Expanded paths
        Returns:
            path_list (list): Expanded paths without cycles.

"""

    copy = path_list.copy()
    for path in path_list:

        for i, j in enumerate(path.route):
            if j in path.route[i + 1:]:
                copy.remove(path)

        path_list = copy

    return path_list
コード例 #6
0
 def compare(expect, result):
     copy = result[:]
     for item in expect:
         if item in copy:
             copy.remove(item)
     return True if not copy else False