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