问题是,我们需要一个硬币抛硬币,而不需要进口任何东西。听起来像是对<some random int> % 2 == 0的测试。最难的部分是<some random int>。可能是堆上的指针?在
input_list = ['a', 'b', 'c', 'd']
#you should empty this once and awhile
fill_my_heap = []
#nothing to see here
class Dummy():
pass
for x in range(0,10):
#give me a new pointer
foo = Dummy()
#prevent reuse of heap memory location
fill_my_heap.append(foo)
#get id of new class and strip its last digit because that was always even
ptr_int = int(str(id(foo))[:-1])
#test to see if this is even. Should be 50% of the time. Sort of... ;)
is_even = ptr_int%2==0
#split list
a = input_list[:len(input_list)/2]
b = input_list[len(input_list)/2:]
#and assemble output based on even-switch
if is_even:
output = a + b
else:
output = b + a
print(output)
Python2型
Python3版
^{pr2}$如果您不喜欢导入,简单的LCG很容易编写代码:
然后:
^{pr2}$这很有趣!禁止进口!在
问题是,我们需要一个硬币抛硬币,而不需要进口任何东西。听起来像是对
<some random int> % 2 == 0
的测试。最难的部分是<some random int>
。可能是堆上的指针?在给出:
^{pr2}$相关问题 更多 >
编程相关推荐