我在 Codeforces 上遇到一个简单的问题,问题是这样的。我想讨论的不是问题,而是我们使用的语言,在本例中是 Python3 和 Haskell。
具体来说,我的算法有两个版本,一个在 Haskell 中,另一个在 Python3 中。两者都采用函数式编程风格。代码看起来像这样
Python3
from operator import add
from itertools import accumulate
from functools import reduce
def floss(l):
def e(u):
a, b = u
return b if a % 2 == 1 else -b
return map(e, enumerate(l))
def flock(l):
return accumulate(l, add)
def search(l):
b = zip(l, l[1:])
def equal(u):
x, y = u
return x == y
c = any(map(equal, b))
return 'YES\n' if c else 'NO\n'
def main(): …Run Code Online (Sandbox Code Playgroud) haskell ×1