The Python Challenge - Level 10

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

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!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 = ''
Hugo로 만듦
Jimmy의 Stack 테마 사용 중