以尽可能少的字符生成Fibonacci序列.任何语言都可以,除了您使用一个运算符定义的语言f,它会打印斐波那契数字.
起点:25 14个字符的哈斯克尔:
f=0:1:zipWith(+)f(tail f)
f=0:scanl(+)1f
Run Code Online (Sandbox Code Playgroud) 在课堂上,我们了解了暂停问题,图灵机器,减少等等.许多同学都说这些都是抽象和无用的概念,而且知道它们并没有真正的意义(即,一旦课程结束,你就会忘记它们结束而不是失去任何东西).
为什么理论有用?你有没有在日常编码中使用它?
输入:
intersperse(666, ["once", "upon", "a", 90, None, "time"])
Run Code Online (Sandbox Code Playgroud)
输出:
["once", 666, "upon", 666, "a", 666, 90, 666, None, 666, "time"]
Run Code Online (Sandbox Code Playgroud)
什么是最优雅的(阅读:Pythonic)写作方式intersperse?
当程序结束时,我希望它说"按任意键继续...",这样我就可以滚动输出了.
我在Python上对大型数据库进行一些查询,以从数据库中获取一些统计信息.我希望这些统计数据在内存中,以便其他程序可以使用它们而无需访问数据库.
我正在考虑如何构造它们,并且在尝试设置一些复杂的嵌套字典之后,我意识到一个好的表示形式将是一个SQL表.但是,我不想将数据存储回持久数据库.是否有支持使用SQL语法查询数据的SQL数据库的内存实现?
我正在尝试制作尽可能便携的可执行文件.删除一些依赖项后,我在另一个系统上运行二进制文件时遇到以下情况:
/lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.15' not found (required by foob)
/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.15' not found (required by foob)
/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by foob)
Run Code Online (Sandbox Code Playgroud)
我更喜欢我的二进制文件不要求用户升级他们的libc版本,所以我也想删除这个依赖项.
生成上述二进制文件的链接器标志已包含在内-static-libgcc -static-libstdc++.为什么二进制文件仍然需要共享的libc.so.6?
我也尝试添加-static标志,但是当我尝试运行该二进制文件时,结果非常奇怪:
$ ls -l foob
-rwxr-xr-x 1 claudiu claudiu 13278191 Oct 10 13:03 foob
$ ./foob
bash: ./foob: No such file or directory
Run Code Online (Sandbox Code Playgroud)
该怎么办?
编辑:
$ file foob
foob: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked (uses shared libs), …Run Code Online (Sandbox Code Playgroud) 我正在setup.py为一个带有一些Cython扩展模块的项目创建一个文件.
我已经让这个工作了:
from setuptools import setup, Extension
from Cython.Build import cythonize
setup(
name=...,
...,
ext_modules=cythonize([ ... ]),
)
Run Code Online (Sandbox Code Playgroud)
安装很好.但是,这假设已安装Cython.如果没有安装怎么办?我知道这是setup_requires参数的用途:
from setuptools import setup, Extension
from Cython.Build import cythonize
setup(
name=...,
...,
setup_requires=['Cython'],
...,
ext_modules=cythonize([ ... ]),
)
Run Code Online (Sandbox Code Playgroud)
但是,如果尚未安装Cython,这当然会失败:
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 2, in <module>
from Cython.Build import cythonize
ImportError: No module named Cython.Build
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是什么?我Cython只setup_requires需要Cython在步骤运行后以某种方式导入,但我需要为了指定ext_modules值.
我现在试图将我的代码保持在80或更少,因为我认为它在大多数情况下看起来更美观.但有时,如果我必须在奇怪的地方放置换行符,代码最终会变得更糟.
有一件事我还没弄清楚如何处理非常好的是长串.例如:
#0.........1........2........3........4.........5.........6.........7.........8xxxxxxxxx9xxxxxx
def foo():
if conditional():
logger.info("<Conditional's meaning> happened, so we're not setting up the interface.")
return
#.....
Run Code Online (Sandbox Code Playgroud)
结束了!将它放在下一行也无济于事:
#0.........1........2........3........4.........5.........6.........7.........8xxxxxxxxx9xxxxxx
def foo():
if conditional():
logger.info(
"<Conditional's meaning> happened, so we're not setting up the interface.")
return
#.....
Run Code Online (Sandbox Code Playgroud)
我可以使用换行但看起来很糟糕:
#0.........1........2........3........4.........5.........6.........7.........8
def foo():
if conditional():
logger.info(
"<Conditional's meaning> happened, so we're not setting \
up the interface.")
return
#.....
Run Code Online (Sandbox Code Playgroud)
该怎么办?缩短字符串是一种选择,但我不希望我的消息的可读性受到与该代码恰好有多少缩进级别一样任意的影响.
boost::to_string(发现于boost/exception/to_string.hpp)的目的是什么?它boost::lexical_cast<std::string>和它有什么不同std::to_string?
考虑一下代码:
int const x = 50;
int const& y = x;
cout << std::is_const<decltype(x)>::value << endl; // 1
cout << std::is_const<decltype(y)>::value << endl; // 0
Run Code Online (Sandbox Code Playgroud)
这是有道理的,因为y不是const参考,它是对a的引用const.
有没有foo这样std::foo<decltype(y)>::value的1?如果没有,那么定义我自己的是什么样的呢?
python ×4
c++ ×3
batch-file ×1
boost ×1
build ×1
c ×1
code-golf ×1
coding-style ×1
computation ×1
const ×1
cython ×1
database ×1
fibonacci ×1
gcc ×1
glibc ×1
lexical-cast ×1
list ×1
readability ×1
setuptools ×1
shell ×1
sql ×1
std ×1
theory ×1
tostring ×1
types ×1
windows ×1