这是一个简单的程序,用于解决CodeJam的recycled numbers(我知道它可以改进)。
它适用于CPython,但与PyPy v1.8崩溃并出现错误:
RPython traceback:
File "jit_metainterp_compile.c", line 19477, in send_loop_to_backend
File "jit_backend_x86_assembler.c", line 2293, in Assembler386_assemble_loop
File "jit_backend_x86_regalloc.c", line 462, in RegAlloc_prepare_loop
File "jit_backend_x86_regalloc.c", line 1027, in RegAlloc__prepare
File "jit_backend_x86_regalloc.c", line 3657, in RegAlloc__compute_vars_longevity
Fatal RPython error: AssertionError
[1] 8440 abort pypy cj.py
代码:
#!/usr/bin/env python2
def permutations(a,b,x):
y = str(x)
cnt = 0
for i in range(1,len(y)):
j = int(y[i:]+y[:i])
if j == x:
break
elif j > x and j >= a and j <= b:
cnt += 1
return cnt
nc = int(raw_input())
for c in xrange(nc):
a, b = map(int,raw_input().split())
cnt = 0
for i in range(a,b+1):
cnt += permutations(a,b,i)
print "Case #%i: %i" % (c+1, cnt)
示例输入:
4
1 9
10 40
100 500
1111 2222