一般编程题
1 class Dragons: 2 def snaug(self, initialFood, rounds): 3 neighbors = [[2,3,4,5], [2,3,4,5], [0,1,4,5], [0,1,4,5], [0,1,2,3], [0,1,2,3]] 4 amounts = [x for x in initialFood] 5 for i in range(rounds): 6 a = [0, 0, 0, 0, 0, 0] 7 for k in range(0, 6): 8 for j in range(0, 4): 9 a[k] += amounts[neighbors[k][j]] # / 4 10 amounts = a 11 12 x = amounts[2] 13 y = 2 * rounds 14 for i in range(0, 2*rounds): 15 if x % 2 == 0: 16 x = x / 2 17 y = y - 1 18 else: 19 break 20 21 if y == 0: 22 return str(int(x)) 23 else: 24 return str(int(x)) + '/' + str(2**y) 25 26 27 # test 28 o = Dragons() 29 30 # test case 31 assert(o.snaug((0, 0, 4, 0, 0, 0), 2) == "1") 32 assert(o.snaug((0, 0, 4, 0, 0, 0), 3) == '1/2') 33 34 print('ok')