Created
August 8, 2020 18:21
-
-
Save marccane/e361265e4e1b3eeb6485be125f4062f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
#Checks if the solution of the tiles problem is valid | |
import sys | |
if len(sys.argv) != 3: | |
print("Usage: ", sys.argv[0], "<tilesProblemFile> <tilesSolutionFile>") | |
sys.exit(2) | |
f=open(sys.argv[1]) | |
liniesTiles=f.readlines() | |
f2=open(sys.argv[2]) | |
liniesSolucio=f2.readlines() | |
#ULL! els index del fitxer solucio comencen per 1, pero com que "stubejem" la primera posicio de les tiles amb els parametres del problema queda compensat | |
numTiles, numColors, amplada, alcada = [int(i) for i in liniesTiles[0].split(" ")] | |
liniesTilesInt = [[int(i) for i in linia.split(" ")] for linia in liniesTiles] | |
tiles = liniesTilesInt | |
liniesSolInt = [[int(i) for i in linia.split(" ")[:-1]] for linia in liniesSolucio] | |
#format tiles: <color nord, c. est, c. sud, c. oest> sentit horari, vamos | |
nord = 0; est = 1; sud = 2; oest = 3 | |
errorGreu = False | |
if len(liniesSolInt) != alcada: | |
print("Warning: alçada incorrecte. ",len(liniesSolInt), alcada) | |
for y in range(len(liniesSolInt)): | |
liniaSolucio = liniesSolInt[y] | |
if y == 0 and len(liniaSolucio) != amplada: | |
print("Warning: amplada incorrecte") | |
for x in range(len(liniaSolucio)): | |
tileId = liniaSolucio[x] | |
if x > 0 and tiles[tileId][oest] != tiles[liniaSolucio[x-1]][est]: | |
print("-->ERROR<--: solucio incorrecta. hor. fila:", y, " columna: ", x) | |
errorGreu = True | |
if y > 0 and tiles[tileId][nord] != tiles[liniesSolInt[y-1][x]][sud]: | |
print("-->ERROR<--: solucio incorrecta. vert. fila:", y, " columna: ", x) | |
errorGreu = True | |
if errorGreu: | |
print("Check: ERROR") | |
sys.exit(1) | |
else: | |
print("Check: OK") | |
sys.exit(0) | |
""" | |
Example tiles problem file: | |
11 4 20 20 | |
1 1 1 2 | |
3 1 3 2 | |
1 2 2 2 | |
4 3 1 3 | |
3 3 4 3 | |
4 4 1 4 | |
1 2 3 4 | |
3 4 3 1 | |
3 1 4 1 | |
2 2 3 1 | |
1 4 1 2 | |
Example solution file: | |
7 2 9 9 8 7 2 9 9 9 9 9 9 9 9 9 9 10 2 9 | |
5 5 4 4 5 5 5 4 4 4 4 4 4 4 4 4 4 5 5 4 | |
6 6 7 11 6 6 6 7 3 11 7 11 7 3 11 7 11 6 6 7 | |
7 1 8 7 11 7 3 2 10 1 8 7 2 10 1 8 7 11 7 2 | |
8 7 2 8 7 2 10 2 8 7 2 9 9 8 7 2 8 7 2 8 | |
5 5 5 5 5 5 5 5 5 5 5 4 4 5 5 5 5 5 5 5 | |
6 6 6 6 6 6 6 6 6 6 6 7 11 6 6 6 6 6 6 6 | |
11 7 11 7 3 11 7 11 7 3 1 8 7 11 7 3 11 7 11 7 | |
1 8 7 2 10 1 8 7 2 10 3 2 8 7 2 10 1 8 7 2 | |
7 2 9 9 8 7 2 9 9 9 10 2 9 9 9 8 7 2 9 9 | |
5 5 4 4 5 5 5 4 4 4 5 5 4 4 4 5 5 5 4 4 | |
6 6 7 11 6 6 6 7 3 11 6 6 7 3 11 6 6 6 7 1 | |
7 1 8 7 11 7 3 2 10 11 7 3 2 10 11 7 3 1 8 7 | |
8 7 2 8 7 2 10 2 8 7 2 10 2 8 7 2 10 3 2 8 | |
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 2 9 | |
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 4 | |
3 11 7 11 7 3 11 7 11 7 3 11 7 3 11 7 11 6 6 7 | |
10 1 8 7 2 10 1 8 7 2 10 3 2 10 1 8 7 11 7 2 | |
8 7 2 9 9 8 7 2 9 9 9 10 2 8 7 2 8 7 2 8 | |
5 5 5 4 4 5 5 5 4 4 4 5 5 5 5 5 5 5 5 5 | |
""" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment