Write in separate folders

This commit is contained in:
Mattéo Delabre 2021-01-27 19:26:06 +01:00
parent d969624ff9
commit d77b88ef9f
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
2 changed files with 44 additions and 35 deletions

View File

@ -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

64
run.py
View File

@ -1,37 +1,37 @@
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(
(
("1", "1"),
("42", "42"),
("1984", "1984"),
),
max_length=3,
processes=processes,
timeout=timeout,
out_log=out_log,
out_invalid=out_invalid
)
print("Candidates:", identity)
print("\nSearching for identity")
identity = autogolf.find_script(
(
("1", "1"),
("42", "42"),
("1984", "1984"),
),
max_length=3,
processes=processes,
timeout=timeout,
invalid_prefix=invalid_prefix,
out_log=out_log,
)
print("Candidates:", identity)
print("\nSearching for successor")
successor = autogolf.find_script(
(
("1", "2"),
("42", "43"),
("1984", "1985"),
),
max_length=5,
processes=processes,
timeout=timeout,
out_log=out_log,
out_invalid=out_invalid
)
print("Candidates:", successor)
print("\nSearching for successor")
successor = autogolf.find_script(
(
("1", "2"),
("42", "43"),
("1984", "1985"),
),
max_length=5,
processes=processes,
timeout=timeout,
invalid_prefix=invalid_prefix,
out_log=out_log,
)
print("Candidates:", successor)