I want to write a cleaner versio*version of this code. It's about two different rows consisting of numbers that have to be weaved. I have already asked this question at this link, but I have translated my code in English so that it's maybe easier to help me improve it.
I want to write a cleaner versio* of this code. It's about two different rows consisting of numbers that have to be weaved. I have already asked this question at this link, but I have translated my code in English so that it's maybe easier to help me improve it.
I want to write a cleaner version of this code. It's about two different rows consisting of numbers that have to be weaved. I have already asked this question at this link, but I have translated my code in English so that it's maybe easier to help me improve it.
I want to write a cleaner versio* of this code. It's about two different rows consisting of numbers that have to be weaved. I have already asked this question at this link, but I have translated my code in English so that it's maybe easier to help me improve it.
I want to write a cleaner versio* of this code. It's about two different rows consisting of numbers that have to be weaved. I have already asked this question at this link, but I have translated my code in English so that it's maybe easier to help me improve it.
I want to write a cleaner versioncleaner versio* of thethis code shown below. It's about two different rows consisting of numbers that have to be weaved. I I have already asked this question at this link, but I have translated my code in English so that it's maybe easier to help me improve it.
It's for an assignment for a course i'mI'm currently following. This is the assignment:
Traveler, if riches are to be achieved, the solution only has to be weaved.
Traveler, if riches are to be achieved, the solution only has to be weaved.
5,4 4,5 8,7
Weave 6,3 3,2 9,6 4,3
Weave 7,6
Weave 9,8
Weave 5,5 7,8 6,5 6,4
5,4 4,5 8,7
Weave 6,3 3,2 9,6 4,3
Weave 7,6
Weave 9,8
Weave 5,5 7,8 6,5 6,4
5,4 4,5 8,7=6,3 3,2 9,6 4,3=7,6=9,8=5,5 7,8 6,5 6,4
5,4 4,5 8,7=6,3 3,2 9,6 4,3=7,6=9,8=5,5 7,8 6,5 6,4
6,4
6,5
10,8
8,8
8,6
7,5
7,3
7,4
5,5
4,2
9,7
10,6
5,3
My code is in three files.
6,4
6,5
10,8
8,8
8,6
7,5
7,3
7,4
5,5
4,2
9,7
10,6
5,3
class Coordinate:
def __init__(self, x_coord, y_coord):
self.x_coord = x_coord
self.y_coord = y_coord
def calculate_new_coord(self):
self.x_coord += 1
self.y_coord += 0
return self.x_coord, self.y_coord
class Coordinate:
def __init__(self, x_coord, y_coord):
self.x_coord = x_coord
self.y_coord = y_coord
def calculate_new_coord(self):
self.x_coord += 1
self.y_coord += 0
return self.x_coord, self.y_coord
class CoordinateRow:
def __init__(self, row):
self.row = row
def append(self, coord):
self.row += [coord]
def extend(self, row):
for coordinate in row:
self.row += [coordinate]
def weave(self, weaveRow):
result = CoordinateRow([])
for i in range(len(self.row)):
if i < len(self.row):
result.append(self.row[i])
if i < len(weaveRow.row):
result.append(weaveRow.row[i])
if len(weaveRow.row) > len(self.row): #Als 2e rij(te weaven door 1e rij) groter dan 1e rij(bestaande rij)
result.extend(weaveRow.row[len(self.row):]) #voeg het verschil toe aan result
return result
class CoordinateRow:
def __init__(self, row):
self.row = row
def append(self, coord):
self.row += [coord]
def extend(self, row):
for coordinate in row:
self.row += [coordinate]
def weave(self, weaveRow):
result = CoordinateRow([])
for i in range(len(self.row)):
if i < len(self.row):
result.append(self.row[i])
if i < len(weaveRow.row):
result.append(weaveRow.row[i])
if len(weaveRow.row) > len(self.row): #Als 2e rij(te weaven door 1e rij) groter dan 1e rij(bestaande rij)
result.extend(weaveRow.row[len(self.row):]) #voeg het verschil toe aan result
return result
file_input = file.read()
strip_file = file_input.strip()
splits_file = strip_file.split("=")
from Coordinate import Coordinate
from CoordinateRow import CoordinateRow
def get_weaved_rows(splits_bestand):
rows = []
for i in range(len(splits_bestand)):
rows += [CoordinateRow(splits_bestand[i].split())]
previous_row = rows[0]
for row in rows[1:]:
previous_row = previous_row.weave(row)
return previous_row
def get_new_coordinates(weaved_rows):
for coordinate in weaved_rows.row:
current_coordinates = Coordinate(int(coordinate[0]), int(coordinate[2])) #coordinaat x[0] en y[2] worden int(x,y)
new_coordinates = current_coordinates.calculate_new_coord() #coordinaten (x,y) na verwerking
print '%d,%d' %(new_coordinates[0], new_coordinates[1])
weaved_rows = get_weaved_rows(splits_file)
get_new_coordinates(weaved_rows)
file_input = file.read()
strip_file = file_input.strip()
splits_file = strip_file.split("=")
from Coordinate import Coordinate
from CoordinateRow import CoordinateRow
def get_weaved_rows(splits_bestand):
rows = []
for i in range(len(splits_bestand)):
rows += [CoordinateRow(splits_bestand[i].split())]
previous_row = rows[0]
for row in rows[1:]:
previous_row = previous_row.weave(row)
return previous_row
def get_new_coordinates(weaved_rows):
for coordinate in weaved_rows.row:
current_coordinates = Coordinate(int(coordinate[0]), int(coordinate[2])) #coordinaat x[0] en y[2] worden int(x,y)
new_coordinates = current_coordinates.calculate_new_coord() #coordinaten (x,y) na verwerking
print '%d,%d' %(new_coordinates[0], new_coordinates[1])
weaved_rows = get_weaved_rows(splits_file)
get_new_coordinates(weaved_rows)
I want to write a cleaner version of the code shown below. It's about two different rows consisting of numbers that have to be weaved. I have already asked this question at this link, but I have translated my code in English so that it's maybe easier to help me improve it.
It's for an assignment for a course i'm currently following. This is the assignment:
Traveler, if riches are to be achieved, the solution only has to be weaved.
5,4 4,5 8,7
Weave 6,3 3,2 9,6 4,3
Weave 7,6
Weave 9,8
Weave 5,5 7,8 6,5 6,4
5,4 4,5 8,7=6,3 3,2 9,6 4,3=7,6=9,8=5,5 7,8 6,5 6,4
6,4
6,5
10,8
8,8
8,6
7,5
7,3
7,4
5,5
4,2
9,7
10,6
5,3
My code is in three files.
class Coordinate:
def __init__(self, x_coord, y_coord):
self.x_coord = x_coord
self.y_coord = y_coord
def calculate_new_coord(self):
self.x_coord += 1
self.y_coord += 0
return self.x_coord, self.y_coord
class CoordinateRow:
def __init__(self, row):
self.row = row
def append(self, coord):
self.row += [coord]
def extend(self, row):
for coordinate in row:
self.row += [coordinate]
def weave(self, weaveRow):
result = CoordinateRow([])
for i in range(len(self.row)):
if i < len(self.row):
result.append(self.row[i])
if i < len(weaveRow.row):
result.append(weaveRow.row[i])
if len(weaveRow.row) > len(self.row): #Als 2e rij(te weaven door 1e rij) groter dan 1e rij(bestaande rij)
result.extend(weaveRow.row[len(self.row):]) #voeg het verschil toe aan result
return result
file_input = file.read()
strip_file = file_input.strip()
splits_file = strip_file.split("=")
from Coordinate import Coordinate
from CoordinateRow import CoordinateRow
def get_weaved_rows(splits_bestand):
rows = []
for i in range(len(splits_bestand)):
rows += [CoordinateRow(splits_bestand[i].split())]
previous_row = rows[0]
for row in rows[1:]:
previous_row = previous_row.weave(row)
return previous_row
def get_new_coordinates(weaved_rows):
for coordinate in weaved_rows.row:
current_coordinates = Coordinate(int(coordinate[0]), int(coordinate[2])) #coordinaat x[0] en y[2] worden int(x,y)
new_coordinates = current_coordinates.calculate_new_coord() #coordinaten (x,y) na verwerking
print '%d,%d' %(new_coordinates[0], new_coordinates[1])
weaved_rows = get_weaved_rows(splits_file)
get_new_coordinates(weaved_rows)
I want to write a cleaner versio* of this code. It's about two different rows consisting of numbers that have to be weaved. I have already asked this question at this link, but I have translated my code in English so that it's maybe easier to help me improve it.
It's for an assignment for a course I'm currently following:
Traveler, if riches are to be achieved, the solution only has to be weaved.
5,4 4,5 8,7
Weave 6,3 3,2 9,6 4,3
Weave 7,6
Weave 9,8
Weave 5,5 7,8 6,5 6,4
5,4 4,5 8,7=6,3 3,2 9,6 4,3=7,6=9,8=5,5 7,8 6,5 6,4
6,4
6,5
10,8
8,8
8,6
7,5
7,3
7,4
5,5
4,2
9,7
10,6
5,3
class Coordinate:
def __init__(self, x_coord, y_coord):
self.x_coord = x_coord
self.y_coord = y_coord
def calculate_new_coord(self):
self.x_coord += 1
self.y_coord += 0
return self.x_coord, self.y_coord
class CoordinateRow:
def __init__(self, row):
self.row = row
def append(self, coord):
self.row += [coord]
def extend(self, row):
for coordinate in row:
self.row += [coordinate]
def weave(self, weaveRow):
result = CoordinateRow([])
for i in range(len(self.row)):
if i < len(self.row):
result.append(self.row[i])
if i < len(weaveRow.row):
result.append(weaveRow.row[i])
if len(weaveRow.row) > len(self.row): #Als 2e rij(te weaven door 1e rij) groter dan 1e rij(bestaande rij)
result.extend(weaveRow.row[len(self.row):]) #voeg het verschil toe aan result
return result
file_input = file.read()
strip_file = file_input.strip()
splits_file = strip_file.split("=")
from Coordinate import Coordinate
from CoordinateRow import CoordinateRow
def get_weaved_rows(splits_bestand):
rows = []
for i in range(len(splits_bestand)):
rows += [CoordinateRow(splits_bestand[i].split())]
previous_row = rows[0]
for row in rows[1:]:
previous_row = previous_row.weave(row)
return previous_row
def get_new_coordinates(weaved_rows):
for coordinate in weaved_rows.row:
current_coordinates = Coordinate(int(coordinate[0]), int(coordinate[2])) #coordinaat x[0] en y[2] worden int(x,y)
new_coordinates = current_coordinates.calculate_new_coord() #coordinaten (x,y) na verwerking
print '%d,%d' %(new_coordinates[0], new_coordinates[1])
weaved_rows = get_weaved_rows(splits_file)
get_new_coordinates(weaved_rows)