Exemplo n.º 1
0
 def __init__(self, numRows, numCols):
     """
     Implementation of the Matrix ADT using a 2-D array. Cre
     -ates a matrix of size numRows*numCols initialized to 0.
     """
     self._theGrid = Array2D(numRows, numCols)
     self._theGrid.clear(0)
Exemplo n.º 2
0
 def __init__(self, rens, cols, pasillos, entrada, salida):
     self.__laberinto = Array2D(rens,cols,'1')
     for pasillo in pasillos:
         self.__laberinto.set_item(pasillo[0],pasillo[1], '0')
     self.set_entrada(entrada[0],entrada[1])
     self.set_salida(salida[0],salida[1])
     self.__camino = Stack()
     self.__previa = None #Guarda la posicion previa
Exemplo n.º 3
0
 def __init__(self, rens, cols, pasillos, entrada, salida):
     self.__laberinto = Array2D(rens, cols, "1")
     for pasillo in pasillos:
         self.__laberinto.set_item(pasillo[0], pasillo[1], "0")
     self.set_entrada(entrada[0], entrada[1])
     self.set_salida(salida[0], salida[1])
     self.__camino = Stack()
     self.__previa = None  #Para obtener el elemento anterior del elemento actual en la pila
Exemplo n.º 4
0
 def __init__(self,rens,cols,pasillos,entrada,salida):
     self.__laberinto = Array2D(rens, cols, "1")
     for pasillo in pasillos:
         self.__laberinto.set_item(pasillo[0] ,pasillo[1] ,"0")
     self.set_entrada(entrada[0],entrada[1])
     self.set_salida(salida[0],salida[1])
     self.__camino = Stack()
     self.__previa = None
Exemplo n.º 5
0
 def __init__(self, cur_array=None):
     """
     Initializes a new Board
     """
     self.board = Array2D(3, 3)
     self.last_position = None
     self.last_symbol = None
     if cur_array is not None:
         for i in range(cur_array.num_cols()):
             for j in range(cur_array.num_rows()):
                 self.board[i, j] = cur_array[i, j]
Exemplo n.º 6
0
 def __init__(self, rens, cols, pasillos):
     self.__laberinto = Array2D(rens,cols,'1')
     for pasillo in pasillos:
         self.__laberinto.set_item(pasillo[0],pasillo[1], '0')
Exemplo n.º 7
0
from array2d import Array2D

# Open the text file for reading.
gradeFile = open(filename, "r")

# Extract the first two values which indicate the size of the array.
numExams = int(gradeFile.readline())
numstudents = int(gradeFile.readline())

# Create the 2D array to store the grades.
examGrades = Array2D(numStudents, numExams)

# Extract the grades from the remaining lines.
i = 0
for student in gradeFile:
    grades = student.split()
    for j in range(numExams):
        examGrades[i, j] = int(grades[j])
    i += 1
gradeFile.close()

# Compute each student's average exam grade.
for i in range(numStudents):
    # tally the exam grades for the ith student
    total = 0
    for j in range(numExams):
        total += examGrades[i, j]

    # Compute average for the ith student.
    examAvg = total // numExams
    print("%2d: %6.2f" % (i + 1, examAvg))
 def __init__(self, num_rows, num_cols):
     """Creates a matrix of size numRows x numCols initialized to 0."""
     self._grid = Array2D(num_rows, num_cols)
     self._grid.clear(0)
Exemplo n.º 9
0
 def __init__(self, numRows, numCols):
     self._theGrid = Array2D(numRows, numCols)
     self._theGrid.clear(0)
Exemplo n.º 10
0
from pathway import Pathway
import sys

sys.setrecursionlimit(100000)
#创建array
row0 = [8, 7, 6, 5]
row1 = [1, 2, 3, 4]
row2 = [9, 10, 11, 12]
row3 = [13, 14, 15, 0]

rowt0 = [1, 2, 3, 4]
rowt1 = [6, 5, 7, 8]
rowt2 = [9, 10, 11, 12]
rowt3 = [13, 14, 15, 0]

array_origin = Array2D(row0, row1, row2, row3)
array_1 = Array2D(row0, row1, row2, row3)
array_target = Array2D(rowt0, rowt1, rowt2, rowt3)

pathway = Pathway()
pathways = []
step_limit = 9999

array_origin.recursion2(array_origin, array_target, pathway, pathways,
                        step_limit)

for pathway in pathways:
    print('\nResult:', pathway.getPathway())

#main:
from array2d import Array2D


if __name__ == '__main__':
    # Open the text file for reading.
    grade_file = open("grades.txt", "r")

    # Extract the first two values which indicate the size of the array.
    num_exams = int(grade_file.readline())
    num_students = int(grade_file.readline())

    # Create the 2-D array to store the grades.
    exam_grades = Array2D(num_students, num_exams)

    # Extract the grades from the remaining lines.
    i = 0
    for student in grade_file:
        grades = student.split()
        for j in range(num_exams):
            exam_grades[i, j] = int(grades[j])
        i += 1
    # Close the text file.
    grade_file.close()
Exemplo n.º 12
0
 def __init__(self, rens, cols, pasillos):
     #0 pasillo, 1 pared, S salida y E entrada
     #pasillo es una tupla ((2,1),(2,2),(2,3),(2,4),(3,2),(4,2))
     self.__laberinto = Array2D(rens, cols, "1")
     for pasillo in pasillos:
         self.__laberinto.set_item(pasillo[0], pasillo[1], "0")