Created
November 5, 2015 17:28
-
-
Save yumechi/bb46ba7b0dc903c23de4 to your computer and use it in GitHub Desktop.
Random generator input and output files for one input value and one return value problems.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1変数が与えられて,1変数で応えるような問題の入力ファイルと回答ファイルをランダムに生成するスクリプト | |
import os | |
import time | |
import random | |
# 想定される答えを出せるスクリプトを描く | |
# 引数とかも適宜調整する | |
# 例:[1, N]の範囲の3または5の倍数の数を答えにした時 (範囲:1<=N<=10*9) | |
def ansfunc(N): | |
return N // 3 + N // 5 - N // 15 | |
def writefiles(dirpath, filename, num): | |
filepath = dirpath + "/" + filename | |
filewriter = open(filepath, "w") | |
filewriter.write(str(num) + "\n") | |
filewriter.close() | |
def createData(number): | |
# フォルダ名の設定 ここでは現在時間とした | |
rootdir = str(int(time.time())) | |
inputdirpath = rootdir + "/input" | |
outputdirpath = rootdir + "/output" | |
os.makedirs(inputdirpath) | |
os.makedirs(outputdirpath) | |
for i in range(1, number+1): | |
# 入力可能な変数の範囲に合わせて適当に変数を決める | |
questionN = int(random.randint(1, 10 ** 9 + 1) // abs(i - number - 1)) // abs(i - number - 1) | |
answer = ansfunc(questionN if questionN > 1 else 1) | |
inputfilename = "input" + str(i) + ".txt" | |
writefiles(inputdirpath, inputfilename, questionN) | |
outputfilename = "output" + str(i) + ".txt" | |
writefiles(outputdirpath, outputfilename, answer) | |
def run(): | |
# 引数に作りたいテストケース数を渡す | |
createData(20) | |
if __name__ == "__main__": | |
print("start!") | |
run() | |
print("end!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment