46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
puzzle_number = input("What is the puzzle ID: ")
|
|
puzzle_name = input("What is the puzzle name (Snake Case): ")
|
|
boilerplate = open(".\\src\\solutions\\xx.rs", "r").read()
|
|
|
|
names = puzzle_name.split('_')
|
|
new_names = list()
|
|
|
|
for name in names:
|
|
new_names.append(name.capitalize())
|
|
|
|
boilerplate = boilerplate.replace("xx", puzzle_name)
|
|
boilerplate = boilerplate.replace("0", puzzle_number)
|
|
boilerplate = boilerplate.replace("XX", "".join(new_names))
|
|
|
|
# Get 3 test inputs
|
|
for i in range(1, 4):
|
|
test_input = input("Test Input for test {}: ".format(i))
|
|
test_result = input("What is the test result for test {}: ".format(i))
|
|
test_file = open(".\\src\\input\\{}_test{}".format(puzzle_number, i), "w")
|
|
test_file.write(test_input)
|
|
boilerplate = boilerplate.replace("Ready", test_result, 1)
|
|
|
|
new_code = open(".\\src\\solutions\\{}.rs".format(puzzle_name), "w")
|
|
new_code.write(boilerplate)
|
|
|
|
# Edit main file to add the new puzzle
|
|
main_file = open(".\\src\\main.rs", "r+", encoding="utf-8")
|
|
main_file_contents = main_file.read()
|
|
old_puzzles = "Box::new(xx::XX {}),"
|
|
new_puzzles = "Box::new(" + puzzle_name + "::" + "".join(new_names) + " {}),\n Box::new(xx::XX {}),"
|
|
main_file_contents = main_file_contents.replace(old_puzzles, new_puzzles)
|
|
main_file.truncate(0)
|
|
main_file.seek(0)
|
|
main_file.write(main_file_contents)
|
|
|
|
|
|
# Edit mode file to expose the new solution
|
|
mod_file = open(".\\src\\solutions\\mod.rs", "r+", encoding="utf-8")
|
|
mod_file_contents = mod_file.read()
|
|
old_mod = "pub mod xx;"
|
|
new_mod = "pub mod " + puzzle_name + ";\npub mod xx;"
|
|
mod_file_contents = mod_file_contents.replace(old_mod, new_mod)
|
|
mod_file.truncate(0)
|
|
mod_file.seek(0)
|
|
mod_file.write(mod_file_contents)
|