myusername的https://aventofcode.com解决方案/
advent-of-code-sample的Python项目详细描述
代码示例的出现:
提供一个工作示例插件结构,用于使用由advent-of-code-data提供的aoc
运行器脚本。
通过aoc
运行程序,您可以轻松地针对多个数据集验证您的Advent of Code解决方案,或者针对自己的数据集验证其他用户的代码。
$ cat ~/.config/aocd/tokens.json # create this file with some auth tokens{"github": "53616c7465645f5f0775...", "google": "53616c7465645f5f7238...", "reddit": "53616c7465645f5ff7c8...", "twitter": "53616c7465645f5fa524..."} $ pip install ~/src/advent-of-code-sample # install the directory which contains your setup.py file ... $ pip install -q advent-of-code-wim # can also install some other user's code if you want..? ... $ aoc --years 2015 --days 3411# run it!0.25s 2015/3 - Perfectly Spherical Houses in a Vacuum wim/github ✔ part a: 2565 ✔ part b: 26390.11s 2015/3 - Perfectly Spherical Houses in a Vacuum wim/google ✔ part a: 2592 ✔ part b: 23600.12s 2015/3 - Perfectly Spherical Houses in a Vacuum wim/reddit ✔ part a: 2592 ✔ part b: 23600.12s 2015/3 - Perfectly Spherical Houses in a Vacuum wim/twitter ✔ part a: 2565 ✔ part b: 26390.12s 2015/3 - Perfectly Spherical Houses in a Vacuum myusername/github ✖ part a: 1234(expected: 2565) ✖ part b: 5678(expected: 2639)0.12s 2015/3 - Perfectly Spherical Houses in a Vacuum myusername/google ✖ part a: 1234(expected: 2592) ✖ part b: 5678(expected: 2360)0.11s 2015/3 - Perfectly Spherical Houses in a Vacuum myusername/reddit ✖ part a: 1234(expected: 2592) ✖ part b: 5678(expected: 2360)0.11s 2015/3 - Perfectly Spherical Houses in a Vacuum myusername/twitter ✖ part a: 1234(expected: 2565) ✖ part b: 5678(expected: 2639)9.04s 2015/4 - The Ideal Stocking Stuffer wim/github ✔ part a: 254575 ✔ part b: 103873625.43s 2015/4 - The Ideal Stocking Stuffer wim/google ✔ part a: 117946 ✔ part b: 393803812.20s 2015/4 - The Ideal Stocking Stuffer wim/reddit ✔ part a: 254575 ✔ part b: 103873647.67s 2015/4 - The Ideal Stocking Stuffer wim/twitter ✔ part a: 282749 ✔ part b: 99626240.12s 2015/4 - The Ideal Stocking Stuffer myusername/github ✖ part a: 1234(expected: 254575) ✖ part b: 5678(expected: 1038736)0.12s 2015/4 - The Ideal Stocking Stuffer myusername/google ✖ part a: 1234(expected: 117946) ✖ part b: 5678(expected: 3938038)0.12s 2015/4 - The Ideal Stocking Stuffer myusername/reddit ✖ part a: 1234(expected: 254575) ✖ part b: 5678(expected: 1038736)0.12s 2015/4 - The Ideal Stocking Stuffer myusername/twitter ✖ part a: 1234(expected: 282749) ✖ part b: 5678(expected: 9962624)6.17s 2015/11 - Corporate Policy wim/github ✔ part a: vzbxxyzz ✔ part b: vzcaabcc 6.26s 2015/11 - Corporate Policy wim/google ✔ part a: cqjxxyzz ✔ part b: cqkaabcc 4.69s 2015/11 - Corporate Policy wim/reddit ✔ part a: hxbxxyzz ✔ part b: hxcaabcc 5.75s 2015/11 - Corporate Policy wim/twitter ✔ part a: hxbxxyzz ✔ part b: hxcaabcc 0.11s 2015/11 - Corporate Policy myusername/github ✖ part a: 1234(expected: vzbxxyzz) ✖ part b: 5678(expected: vzcaabcc)0.12s 2015/11 - Corporate Policy myusername/google ✖ part a: 1234(expected: cqjxxyzz) ✖ part b: 5678(expected: cqkaabcc)0.11s 2015/11 - Corporate Policy myusername/reddit ✖ part a: 1234(expected: hxbxxyzz) ✖ part b: 5678(expected: hxcaabcc)0.12s 2015/11 - Corporate Policy myusername/twitter ✖ part a: 1234(expected: hxbxxyzz) ✖ part b: 5678(expected: hxcaabcc)
如何插入代码:
运行程序使用setuptools'dynamic discovery of services and plugins功能定位并运行代码。
在setup.py
中定义插件的入口点。要使用的组名是“acventofcode.user”:
# setup.pyfromsetuptoolsimportsetupsetup(...entry_points={"adventofcode.user":["myusername = mypackage:mysolve"]},)
将mypackage
更改为用于导入内容的任何包或模块名称。
名称mysolve
应解析为包命名空间中的可调用名称,该名称接受三个命名参数year
、day
、data
(任何顺序都可以),并返回两个值,例如:
defmysolve(year,day,data):...returnpart_a_answer,part_b_answer
在入口点内,您可以做任何需要的事情来委托给您的代码。例如,将数据写入临时文件,然后运行脚本,或者导入函数,然后直接将数据作为参数传入。 唯一的要求是这个入口点应该返回一个包含两个值的元组,并给出当天谜题的答案,剩下的由您决定。 您可以派生这个repo并对其进行编辑,或者手动编写自己的插件。