Write in separate folders
This commit is contained in:
parent
d969624ff9
commit
d77b88ef9f
|
@ -90,8 +90,8 @@ def find_script(
|
|||
max_length,
|
||||
processes,
|
||||
timeout,
|
||||
invalid_prefix,
|
||||
out_log,
|
||||
out_invalid,
|
||||
) -> List[str]:
|
||||
"""
|
||||
Find scripts that satisfy the given set of test cases.
|
||||
|
@ -100,13 +100,19 @@ def find_script(
|
|||
:param max_length: maximum script length to test
|
||||
:param processes: number of parallel processes to spawn
|
||||
:param timeout: maximum allowed time in seconds for each script run
|
||||
:param invalid_prefix: prefix to the files in which invalid scripts
|
||||
are to be stored, one file per script length
|
||||
:param out_log: stream to which progress logs are written
|
||||
:param out_invalid: stream to which invalid scripts are saved
|
||||
:returns: list of matching scripts
|
||||
"""
|
||||
candidates = []
|
||||
bound_check_script = partial(check_script, pairs, timeout)
|
||||
|
||||
out_invalid = []
|
||||
|
||||
for i in range(max_length + 1):
|
||||
out_invalid.append(open(invalid_prefix + str(i), "w"))
|
||||
|
||||
chars_count = len(chars)
|
||||
num_tasks = int((chars_count ** (max_length + 1) - 1) / (chars_count - 1))
|
||||
done_tasks = 0
|
||||
|
@ -134,6 +140,9 @@ def find_script(
|
|||
candidates.append(script)
|
||||
|
||||
if status == Status.Invalid:
|
||||
print(script, file=out_invalid)
|
||||
print(script, file=out_invalid[len(script)])
|
||||
|
||||
for file in out_invalid:
|
||||
file.close()
|
||||
|
||||
return candidates
|
||||
|
|
28
run.py
28
run.py
|
@ -1,13 +1,13 @@
|
|||
import autogolf
|
||||
import sys
|
||||
|
||||
with open("output/invalid_scripts", "w") as out_invalid:
|
||||
processes = 8
|
||||
timeout = 5 # seconds
|
||||
out_log = sys.stdout
|
||||
processes = 8
|
||||
timeout = 5 # seconds
|
||||
invalid_prefix = "output/invalid_scripts_"
|
||||
out_log = sys.stdout
|
||||
|
||||
print("\nSearching for identity")
|
||||
identity = autogolf.find_script(
|
||||
print("\nSearching for identity")
|
||||
identity = autogolf.find_script(
|
||||
(
|
||||
("1", "1"),
|
||||
("42", "42"),
|
||||
|
@ -16,13 +16,13 @@ with open("output/invalid_scripts", "w") as out_invalid:
|
|||
max_length=3,
|
||||
processes=processes,
|
||||
timeout=timeout,
|
||||
invalid_prefix=invalid_prefix,
|
||||
out_log=out_log,
|
||||
out_invalid=out_invalid
|
||||
)
|
||||
print("Candidates:", identity)
|
||||
)
|
||||
print("Candidates:", identity)
|
||||
|
||||
print("\nSearching for successor")
|
||||
successor = autogolf.find_script(
|
||||
print("\nSearching for successor")
|
||||
successor = autogolf.find_script(
|
||||
(
|
||||
("1", "2"),
|
||||
("42", "43"),
|
||||
|
@ -31,7 +31,7 @@ with open("output/invalid_scripts", "w") as out_invalid:
|
|||
max_length=5,
|
||||
processes=processes,
|
||||
timeout=timeout,
|
||||
invalid_prefix=invalid_prefix,
|
||||
out_log=out_log,
|
||||
out_invalid=out_invalid
|
||||
)
|
||||
print("Candidates:", successor)
|
||||
)
|
||||
print("Candidates:", successor)
|
||||
|
|
Loading…
Reference in New Issue