-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_submission.py
60 lines (44 loc) · 1.73 KB
/
validate_submission.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import argparse
def validate(problines,sublines):
# Read data from the Problem
size = problines[1].split()
M,N = int(size[0]),int(size[1])
valid,error = True,""
pieces = []
for line in sublines:
line = line.strip()
entries = line.split()
if len(entries) > 5:
return False, f"Incorrect Formatting: {line}"
try:
cords = []
for cord in entries[1:]:
x,y = cord.split(',')
cords += [(int(x),int(y))]
except Exception as e:
return False, e
if any([x>=M or y>=N for x,y in cords]):
return False, f"Out of bounds for floor size {M,N}: {line}"
label = entries[0]
pieces += [label]
if len(set(pieces)) < len(pieces):
return False, "Piece used twice. Every piece label can be used at most once"
return True,""
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Validate discreteHack submission")
parser.add_argument('--problem', required=True,help="path to problem file")
parser.add_argument('--submission', required=True,help="path to submission file")
args = parser.parse_args()
print("""This script validates that your submission format is correct.\n It DOES NOT check
piece shapes or forbidden squares.
Usage:\n python validate_submission.py --problem Problem.txt --submission Submission.txt
""")
with open(args.problem,'r') as fin:
problines = fin.readlines()
with open(args.submission,'r') as fin:
sublines = fin.readlines()
valid, error = validate(problines,sublines)
if valid:
print("Submission valid")
else:
print("Submision invalid\n",error)