小编iCo*_*dez的帖子

混淆的C代码竞赛2006.请解释sykes2.c

这个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)

c obfuscation deobfuscation

963
推荐指数
4
解决办法
8万
查看次数

str.startswith,带有要测试的字符串列表

我试图避免使用如此多的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)

任何帮助,将不胜感激.

python string list

154
推荐指数
2
解决办法
11万
查看次数

在Ruby中构建字符串时,为什么铲运算符(<<)比plus-equals(+ =)更受欢迎?

我正在研究Ruby Koans.

about_strings.rb中test_the_shovel_operator_modifies_the_original_stringKoan 包含以下注释:

在构建字符串时,Ruby程序员倾向于使用铲运算符(<<)而不是正等运算符(+ =).为什么?

我的猜测是它涉及速度,但我不明白引擎盖下的动作会导致铲子操作员更快.

有人能够解释这个偏好背后的细节吗?

ruby string optimization

149
推荐指数
6
解决办法
3万
查看次数

Ruby发送vs __send__

我理解这个概念,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)

有人对此有任何想法吗?

ruby syntax

145
推荐指数
4
解决办法
2万
查看次数

Python将元组转换为字符串

我有一个像这样的字符元组:

('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e')
Run Code Online (Sandbox Code Playgroud)

如何将其转换为字符串,使其如下所示:

'abcdgxre'
Run Code Online (Sandbox Code Playgroud)

python string tuples

85
推荐指数
3
解决办法
26万
查看次数

使用哈希时获取与[]的对比?

来自Ruby Koans about_hashes.rb:

为什么可能要使用#fetch而不是#[]在访问哈希键时?

ruby

67
推荐指数
3
解决办法
3万
查看次数

为什么字典可以作为元组解压缩?

今天,我看到一个没有例外的声明.任何人都可以解释它背后的理论吗?

>>> x, y = {'a': 2, 'b': 5}
>>> x
'a'
>>> y
'b'
Run Code Online (Sandbox Code Playgroud)

python dictionary python-2.7 iterable-unpacking

61
推荐指数
5
解决办法
2919
查看次数

如何删除python中字符串中的所有字符实例?

如何删除此字符串中字符的所有实例?这是我的代码:

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)

为什么是这样?

python string replace python-2.7

59
推荐指数
2
解决办法
11万
查看次数

Ruby Koans的test_changing_hashes中的奖金问题的答案是什么?

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

55
推荐指数
1
解决办法
4543
查看次数

shovel(<<)运算符如何在Ruby Hashes中工作?

当我遇到这个时,我正在阅读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 hash

49
推荐指数
2
解决办法
9161
查看次数