用于解决项目euler问题的helper体系结构
pyler的Python项目详细描述
pyler是一个库,它帮助使用python解决project euler问题
怎么做?
$ pip install pyler
生成文件
# generates the file for problem 1$ pyler gen 1# generates the file for problems 1 to 10, 14 and 17 to 24$ pyler gen 1-10,14,17-24 # generates the first not-yet-generated problem $ pyler gen next # generates all available problems $ pyler gen all
你明白了!
这将生成一个文件,其中或多或少包含用于开始实际工作的所有内容。 只需填充变量并将您的解决方案编码到solver中。
frompylerimportEulerProblemclassProblem0001(EulerProblem):""" If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. """problem_id=1simple_input=0simple_output=1real_input=0defsolver(self,input_val):return0if__name__=='__main__':importunittestunittest.main()
您可以使用--path和 与--template=path/to/template.py一起使用的模板,模板文件必须兼容 使用python的[.format](https://pyformat.info/)函数并将收到两个变量:doc 以及problem_id
顺便说一下:是的,docstring是从网站上刮来的。
测试您的溶液
# Tests the implementation of the first problem $ pyler test1# Well I'm sure you know what this does $ pyler test1-10,14,17-24 # Tests the last problem $ pyler test last
您也可以使用unittest或您选择的接受unittest测试用例的测试工具。 直接在问题文件上调用python也将启动测试。
在解决方案模块上启动测试将测试您的解决方案:
- 简单的测试用例(语句中给出的测试用例)
- 真实的测试用例(它将在真实的网站上进行检查)。第一次 时间,它将要求您的凭据(存储在本地文件中 .pyler.conf)然后,它会不时地要求您解决验证码。如果 您已经验证了该问题,它将从 第页。否则,它将为您提交解决方案。
- 确保实现所需时间少于1分钟的测试。如果你是 不使用windows,它将在1分钟后停止。否则,当 计算结束了。
可以将任意数量的--only=x和--skip=x标志与x一起使用 是simple,real,time。