The Python Challenge – Level 10

http://www.pythonchallenge.com/pc/return/bull.html

a = [1, 11, 21, 1211, 111221, ......] 이랜다.
a[30] 값의 길이를 구하라고 하는데......알고보니 개미 수열이군...

#!c:\python26\python.exe

start = str(1)
tmp = start[0]
count = 0
final = ''

print start

for x in range(30):
    for y in range(len(start)):
        if tmp == start[y]:
            count += 1
        else:
            final += str(count) + str(tmp)
            tmp = start[y]
            count = 1

    output = final + str(count) + tmp
    print output

    if x == 29:
        print '###################'
        print 'len(a[30]) = ' + str(len(output))
        print '###################'

    else:
        start = output
        tmp = start[0]
        count = 0
        final = ''
        output = ''

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다