这个C程序如何工作?
main(_){_^448&&main(-~_);putchar(--_%64?32|-~7[__TIME__-_/8%8][">'txiZ^(~z?"-48]>>";;;====~$::199"[_*2&8|_/64]/(_&2?1:8)%8&1:10);}
Run Code Online (Sandbox Code Playgroud)
它按原样进行编译(测试gcc 4.6.3).它打印编译时的时间.在我的系统上:
!! !!!!!! !! !!!!!! !! !!!!!!
!! !! !! !! !! !! !! !!
!! !! !! !! !! !! !! !!
!! !!!!!! !! !! !! !! !! !!!!!!
!! !! !! !! !! !! !!
!! !! !! !! !! !! !!
!! !!!!!! !! !! !! !!!!!!
Run Code Online (Sandbox Code Playgroud)
资料来源:sykes2 - 一行中的一个时钟,sykes2作者提示
一些提示:默认情况下没有编译警告.编译时-Wall,会发出以下警告:
sykes2.c:1:1: warning: return type defaults to ‘int’ [-Wreturn-type]
sykes2.c: In function ‘main’:
sykes2.c:1:14: warning: value …Run Code Online (Sandbox Code Playgroud) 我试图避免使用如此多的if语句和比较,只是使用一个列表,但不知道如何使用它str.startswith:
if link.lower().startswith("js/") or link.lower().startswith("catalog/") or link.lower().startswith("script/") or link.lower().startswith("scripts/") or link.lower().startswith("katalog/"):
# then "do something"
Run Code Online (Sandbox Code Playgroud)
我希望它是:
if link.lower().startswith() in ["js","catalog","script","scripts","katalog"]:
# then "do something"
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
我正在研究Ruby Koans.
about_strings.rb中的test_the_shovel_operator_modifies_the_original_stringKoan 包含以下注释:
在构建字符串时,Ruby程序员倾向于使用铲运算符(<<)而不是正等运算符(+ =).为什么?
我的猜测是它涉及速度,但我不明白引擎盖下的动作会导致铲子操作员更快.
有人能够解释这个偏好背后的细节吗?
我理解这个概念,some_instance.send但我想弄清楚为什么你可以这两种方式调用它.Ruby Koans暗示除了提供许多不同的方法来做同样的事情之外还有一些原因.以下是两个用法示例:
class Foo
def bar?
true
end
end
foo = Foo.new
foo.send(:bar?)
foo.__send__(:bar?)
Run Code Online (Sandbox Code Playgroud)
有人对此有任何想法吗?
我有一个像这样的字符元组:
('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e')
Run Code Online (Sandbox Code Playgroud)
如何将其转换为字符串,使其如下所示:
'abcdgxre'
Run Code Online (Sandbox Code Playgroud) 今天,我看到一个没有例外的声明.任何人都可以解释它背后的理论吗?
>>> x, y = {'a': 2, 'b': 5}
>>> x
'a'
>>> y
'b'
Run Code Online (Sandbox Code Playgroud) 如何删除此字符串中字符的所有实例?这是我的代码:
def findreplace(char, string):
place = string.index(char)
string[place] = ''
return string
Run Code Online (Sandbox Code Playgroud)
但是,如果我运行它,会发生这种情况:
>>> findreplace('i', 'it is icy')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in findreplace
TypeError: 'str' object does not support item assignment
Run Code Online (Sandbox Code Playgroud)
为什么是这样?
在Ruby Koans中,about_hashes.rb部分包含以下代码和注释:
def test_changing_hashes
hash = { :one => "uno", :two => "dos" }
hash[:one] = "eins"
expected = { :one => "eins", :two => "dos" }
assert_equal true, expected == hash
# Bonus Question: Why was "expected" broken out into a variable
# rather than used as a literal?
end
Run Code Online (Sandbox Code Playgroud)
我无法在评论中找出奖金问题的答案 - 我实际上尝试过他们建议的替换,结果是一样的.我可以理解的是,它是为了可读性,但我没有看到像本教程中其他地方所述的一般编程建议.
(我知道这听起来好像已经在某个地方得到了回答,但我无法挖掘任何权威的东西.)
当我遇到这个时,我正在阅读Ruby Koans教程系列about_hashes.rb:
def test_default_value_is_the_same_object
hash = Hash.new([])
hash[:one] << "uno"
hash[:two] << "dos"
assert_equal ["uno", "dos"], hash[:one]
assert_equal ["uno", "dos"], hash[:two]
assert_equal ["uno", "dos"], hash[:three]
assert_equal true, hash[:one].object_id == hash[:two].object_id
end
Run Code Online (Sandbox Code Playgroud)
其中的值assert_equals实际上是教程所期望的.但我无法理解使用<<运算符和=运算符之间有何区别?
我的期望是:
hash[:one] 将会 ["uno"]hash[:two] 将会 ["dos"]hash[:three] 将会 []有人可以解释为什么我的期望是错的吗?
ruby ×5
python ×4
string ×4
python-2.7 ×2
c ×1
dictionary ×1
hash ×1
list ×1
obfuscation ×1
optimization ×1
replace ×1
syntax ×1
tuples ×1