这是(我认为)来自复杂性理论的简单问题。什么是映射缩减函数
#Consider the language E over the binary alphabet
#consisting of strings representing even non-negative
#integers (with leading zeros allowed).
#I.e. E = {x | x[-1] == '0'}.
#
#Reduce E to the language {'Even'} by implementing
#the function R
def R(x):
#Code
def main():
#test cases
assert(R('10010') in ['Even'])
assert(R('110011') not in ['Even'])
if __name__ == '__main__':
main()
根据映射还原DEF:
“语言A是映射还原为语言B,写入A≤的mB, 如果有一个可计算的函数f:Σ* - →Σ*,其中每瓦特, w∈A⇐⇒f(w)∈B。 函数f被称为从A到B的减少。一个可计算的映射函数将是f(n)= 2n(或Python中的x),但在这种情况下,那些断言没有意义,因为每个R(x)应该在{'Even' } ...?
这是(我认为)从作业容易的问题。 – MisterMiyagi