解决Project Euler问题的辅助架构
项目描述
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
你明白了!
这将生成一个包含开始真正工作的几乎所有内容的文件。只需填写变量,并在求解器中编写你的解决方案。
from pyler import EulerProblem
class Problem0001(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 = 1
simple_input = 0
simple_output = 1
real_input = 0
def solver(self, input_val):
return 0
if __name__ == '__main__':
import unittest
unittest.main()
你可以使用 --path 修改文件生成路径,使用 --template=path/to/template.py 修改使用的模板,模板文件必须与Python的 [.format](https://pyformat.info/) 函数兼容,并将接收2个变量: doc 和 problem_id
顺便说一句:是的,文档字符串是从网站上抓取的。
测试你的解决方案
# Tests the implementation of the first problem
$ pyler test 1
# Well I'm sure you know what this does
$ pyler test 1-10,14,17-24
# Tests the last problem
$ pyler test last
您还可以使用unittest或您选择的任何接受unittest TestCases的测试工具。直接在问题文件上调用Python也将启动测试。
在您的解决方案模块上运行测试将测试您的解决方案:
简单的测试用例(在陈述中给出的那个)
真实的测试用例(它将检查真实网站以进行检查)。第一次运行时,它将要求您输入凭据(存储在本地文件 .pyler.conf 中),并且不时会要求您解决验证码。如果您已经验证了问题,它将检查页面上的解决方案。否则,它将为您提交解决方案。
一个测试,确保您的实现时间少于1分钟。如果您不使用Windows,它将在1分钟时停止。否则,计算结束后将失败。
您可以使用任意数量的--only=x和--skip=x标志,其中x为simple、real或time。
项目详情
下载文件
下载您平台对应的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分布
pyler-0.2.0.tar.gz (8.0 kB 查看哈希值)
构建分布
pyler-0.2.0-py3-none-any.whl (5.4 kB 查看哈希值)
关闭
pyler-0.2.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f4c5a99ef2b5ca3db4371c8107f66ba9985d0089fb94b17f652ca87b5a26f24d |
|
MD5 | f520ecdccd75cd07b64c96f5e6cb7f11 |
|
BLAKE2b-256 | 74d55b85750f13e45aea2881fb839e09d449c80c5115358410b7239b9578e5cd |
关闭
pyler-0.2.0-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3b2e2eb2c1ae0b9d16c6c2fda9b166f63514ac0be2696e355e473f951bda3463 |
|
MD5 | 95f65e60526d340b9d989e2598287e4c |
|
BLAKE2b-256 | f84b56b17bea4c62784bd96c3fa87301d1d0eddac0ba7eb34a5cdcbe71d1fbd7 |