跳转到主要内容

解决Project Euler问题的辅助架构

项目描述

PyPI Travis AppVeyor Codecov

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个变量: docproblem_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为simplerealtime

项目详情


下载文件

下载您平台对应的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

pyler-0.2.0.tar.gz (8.0 kB 查看哈希值)

上传时间

构建分布

pyler-0.2.0-py3-none-any.whl (5.4 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWSAWS 云计算和安全赞助商 DatadogDatadog 监控 FastlyFastly CDN GoogleGoogle 下载分析 MicrosoftMicrosoft PSF赞助商 PingdomPingdom 监控 SentrySentry 错误日志 StatusPageStatusPage 状态页面