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

问题描述 投票:1回答: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
python pypy
1个回答
4
投票

这看起来像是一个bug。的确,它可能与这个错误报告有关。

https:/bitbucket.orgpypypyissues1075。

试试最新的夜间。

© www.soinside.com 2019 - 2024. All rights reserved.