在使用CPython时,简单程序(2个循环)在PyPy中崩溃

时间:2012-04-17 21:28:10

标签: python pypy

这是一个简单的程序,用于解决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

1 个答案:

答案 0 :(得分:4)

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

https://bugs.pypy.org/issue1075

每晚尝试一下。