def part2(): boards_copy = copy.copy(boards) uncompleted = [i for i in range(len(boards_copy))] for num in numbers_to_call: # print("---- Checking: %d ----"%num) for idx, board in enumerate(boards_copy): if idx not in uncompleted: continue # print("Checking %d on board %d"%(num,idx)) b2 = check_number_on_board(board, num) if board_is_winner(b2): # print("Winner winner!") # print() # utils.printMatrix(b2, " ") # score = score_board(b2) # print() uncompleted.remove(idx) if len(uncompleted) == 0: print("Only one board left") print("Loser is: %d" % idx) score = score_board(b2) utils.printMatrix(b2, " ") print("Score: %d" % score) print() return score * num # utils.printMatrix(b2, ' ') boards_copy[idx] = b2
def part2(): m = copy.deepcopy(input) utils.printMatrix(input) low_points = [] for y, row in enumerate(m): for x, val in enumerate(row): borders = [] if x > 0: borders.append(row[x-1]) if x + 1 < len(row): borders.append(row[x+1]) if y > 0: borders.append(m[y-1][x]) if y + 1 < len(m): borders.append(m[y+1][x]) if all(b > val for b in borders): # print(x, y, val, borders) # print("--- low point --- ") low_points.append([x,y]) print(low_points) basins = [get_basin_size(p, m) for p in low_points] basins.sort() basins.reverse() print(basins) return basins[0] * basins[1] * basins[2]
def part2(): # cycles = 200 # utils.printMatrix(input) cells = [] for y, row in enumerate(input): cell_row = [] for x, val in enumerate(row): left = None up = None if cell_row: left = cell_row[-1] if cells: up = cells[y - 1][x] cell = Cell(val, x, y, left, up) cell_row.append(cell) # print(cell) cells.append(cell_row) print() utils.printMatrix(cells) i = 0 total_cells = len([c for row in cells for c in row]) while True: i += 1 print("\n---- Step %d ---" % i) score = run_step(cells) print("score: ", score) if (score == total_cells): return i
def part1(): cycles = 100 # utils.printMatrix(input) cells = [] for y, row in enumerate(input): cell_row = [] for x, val in enumerate(row): left = None up = None if cell_row: left = cell_row[-1] if cells: up = cells[y - 1][x] cell = Cell(val, x, y, left, up) cell_row.append(cell) # print(cell) cells.append(cell_row) print() utils.printMatrix(cells) score = 0 for i in range(cycles): # print("\n---- Step %d ---"%i) score += run_step(cells) print(score) # utils.printMatrix(cells) return score
def print_arc(pos_list, g): max_y = max([0] + [p[1] for p in pos_list]) min_y = min(g[1] + [p[1] for p in pos_list]) width = max(g[0][1], max([p[0] for p in pos_list])) height = max_y - min_y print(width, height) m = utils.make2dArray(width + 1, height + 1, ".") # max_y should end up at 0 # min_y should be the full height target_min_y = -g[1][0] + max_y target_max_y = -g[1][1] + max_y print(target_min_y, target_max_y) for y in range(target_max_y, target_min_y + 1): for x in range(g[0][0], g[0][1] + 1): m[y][x] = "T" m[max_y][0] = "S" for p in pos_list: x = p[0] y = -p[1] + max_y m[y][x] = "#" last = pos_list[-1] m[-last[1] + max_y][last[0]] = "█" utils.printMatrix(m)
def goHome(self): x1 = self.getNewCoordinate(0) y1 = self.getNewCoordinate(1) self.current_position = (x1, y1) self.updateSearchMap(self.current_position) self.mutex_search_map.acquire() utils.printMatrix(self.search_map) self.mutex_search_map.release()
def print_path(came_from, current, m): path = reconstruct_path(came_from, current) m1 = utils.make2dArray(len(m[0]), len(m), '.') for p in path: m1[p[1]][p[0]] = "█" # time.sleep(0.1) os.system("clear") utils.printMatrix(m1)
def person(matrix): while True: x = int(input('X: ')) y = int(input('Y: ')) if (matrix[x][y] == '_'): break print('Position has value... Try again...') matrix[x][y] = 'x' printMatrix(matrix)
def move(self, new_position): dx, dy = new_position[0] - self.current_position[0], new_position[ 1] - self.current_position[1] real_dx, real_dy = dx * self.rango_ancho, dy * self.rango_largo #self.bebop.move_relative(real_dx, real_dy, 0, 0) time.sleep(5) self.current_position = new_position self.updateSearchMap(self.current_position) self.mutex_search_map.acquire() utils.printMatrix(self.search_map) self.mutex_search_map.release()
def print_paper(dots): max_x = max([d[0] for d in dots]) max_y = max([d[1] for d in dots]) m = utils.make2dArray(max_x+1, max_y+1, ".") for d in dots: m[d[1]][d[0]] = "#" utils.printMatrix(m)
def part2(): vmap = copy.deepcopy(vent_map) for line in lines: [p0, p1] = line print() print("Checking line: ", p0, p1) vmap = add_line_to_map(vmap, line) utils.printMatrix(vmap) vals = [val for row in vmap for val in row] return sum([1 if t > 1 else 0 for t in vals])
def part1(): utils.printMatrix(input) grid = copy.copy(input) did_move = True i = 0 while did_move: i += 1 (did_move, grid) = do_step(grid) print() print(i) utils.printMatrix(grid) return i
def concWeightSim(maxWeight, maxSent): percentMatrix = [[0 for x in range(maxWeight)] for x in range(maxSent)] for i in range(maxWeight): for j in range(maxSent): percentMatrix[i][j] = fullConcWeight(i, j) print("X-Axis = numSent") print("Y-Axis = weight") utils.printMatrix(percentMatrix) maxPercent, bestWeight, bestNumSent = getMatrixMax(percentMatrix) print("\nBest percentage: " + str(maxPercent), end="") print("\nBest Sentence num: " + str(bestNumSent), end="") print("\nBest Weight: " + str(bestWeight)) # optional graph drawing function drawWeightMatrix(percentMatrix)
def move(self, new_position): verticalMove = self.getDronVerticalAlignment() if properties.ROTATE: rotation_diff = utils.angleDifference(self.current_position, new_position, self.current_rotation) distance_diff = utils.cartesianDistance(self.current_position, new_position) self.bebop.move_relative(0, 0, 0, rotation_diff) time.sleep(2) self.bebop.move_relative(distance_diff, 0, verticalMove, 0) self.current_rotation -= rotation_diff time.sleep(2) else: dx, dy = new_position[0] - self.current_position[0], new_position[1] - self.current_position[1] real_dx, real_dy = dx * self.rango_ancho, dy * self.rango_largo self.bebop.move_relative(real_dx, real_dy, verticalMove, 0) time.sleep(2) self.current_position = new_position self.mutex_search_map.acquire() utils.printMatrix(self.search_map) self.mutex_search_map.release()
def part1(): vmap = copy.deepcopy(vent_map) for line in lines: [p0, p1] = line print() print("Checking line: ", p0, p1) if (p0[0] != p1[0] and p0[1] != p1[1]): # print("Diagonal of some kind") continue else: # Add this to the map vmap = add_line_to_map(vmap, line) utils.printMatrix(vmap) vals = [val for row in vmap for val in row] return sum([1 if t > 1 else 0 for t in vals])
def part1(): m = copy.deepcopy(input) utils.printMatrix(input) low_scores = [] for y, row in enumerate(m): for x, val in enumerate(row): borders = [] if x > 0: borders.append(row[x-1]) if x + 1 < len(row): borders.append(row[x+1]) if y > 0: borders.append(m[y-1][x]) if y + 1 < len(m): borders.append(m[y+1][x]) if all(b > val for b in borders): print(x, y, val, borders) print("--- low point --- ") low_scores.append(val + 1) return sum(low_scores)
def part2(): steps = 50 # print(input) mask = input[0] image = input[2:] img = np.array(image) img = pad_by(img, 2, ".") # utils.printMatrix(img) # print(img) utils.printMatrix(img) for i in range(steps): print(i) edge = img[0][0] img = pad_by(img, 2, edge) img = enhance_image(img, mask) utils.printMatrix(img) return sum([1 if c == "#" else 0 for row in img for c in row])
def part1(): # print(numbers_to_call) # print(boards) # print(len(boards), boards[0]) boards_copy = copy.copy(boards) for num in numbers_to_call: # print("---- Checking: %d ----"%num) for idx, board in enumerate(boards_copy): # print("Checking %d on board %d"%(num,idx)) b2 = check_number_on_board(board, num) if board_is_winner(b2): print("Winner winner!") print() utils.printMatrix(b2, " ") score = score_board(b2) print() return score * num # utils.printMatrix(b2, ' ') boards_copy[idx] = b2
from utils import readMatrixFromFile, copyMatrix, printMatrix from findDeterminate import findDet from findRoot import findRoot print('Task №1: ') A = readMatrixFromFile('input14_A.txt') printMatrix(A, 'A') print('Det A:', findDet(copyMatrix(A)), end='\n\n') B = readMatrixFromFile('input14_B.txt') printMatrix(B, 'B') print('Det B:', findDet(copyMatrix(B)), end='\n\n') C = readMatrixFromFile('input14_C.txt') printMatrix(C, 'C') print('Det C:', findDet(copyMatrix(C)), end='\n\n') print('Task №2: ') findRoot(B)
def print_grid(grid): utils.printMatrix( np.pad(np.array(grid), 1, "constant", constant_values="#"))
matrix[x][y] = 'x' printMatrix(matrix) def computer(matrix, x, y): matrix[x][y] = 'o' printMatrix(matrix) if __name__ == '__main__': board = [['_', '_', '_'], ['_', '_', '_'], ['_', '_', '_']] # value = minimax(board, 'o') # print(value) printMatrix(board) while True: person(board) position = findBestMove(board) computer(board, position[0], position[1]) if (position[2] == 10): print('CLIENT WIN') break if (position[2] == -10): print('COMPUTER WIN') break if (position[0] == 0 and isFullOf(board)): print('DRAW') break
def computer(matrix, x, y): matrix[x][y] = 'o' printMatrix(matrix)