1

这是一个为解决 CodeJam 的回收号码而编写的简单程序(我知道它可以改进)。

它适用于 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
4

1 回答 1

3

这看起来像一个错误。实际上,它可能与此错误报告有关:

https://bitbucket.org/pypy/pypy/issues/1075/

尝试最新的每晚。

于 2012-04-17T21:53:28.413 回答