Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Imamo klasu Zbroj.
- Imamo random elemente medju kojima su instance te klase. Ako te instance daju zbroj od 9000, provjeriti dubinu elementa u kojem se nalaze.
- Naci takav najdublji element po zadanim kriterijima.
- """
- class Zbroj:
- def __init__(self, a, b):
- self.__a = a
- self.__b = b
- def __repr__(self):
- return 'Zbroj(' + str(self.__a) + ', ' + str(self.__b) + ')'
- def vrijednost(self):
- return self.__a + self.__b
- podaci = [[['2F8OfBjd', [[['4z', [70635, ['81HYoC', [Zbroj(1, 15)], Zbroj(10, 11)]], 'xu'], Zbroj(16, 13)], Zbroj(18, 18)], 'tK']], [[[Zbroj(623, 8377)]]], [[['K9O2yIT', Zbroj(17, 0)]]], [[Zbroj(3, 18), [Zbroj(7, 7), 17509]]], [[[Zbroj(5, 8), [['u', [[[[Zbroj(20, 11), [80774, [Zbroj(0, 5)]]]]], 'kWwp9n4Gvo7ClVY']], Zbroj(7, 5)], 'KFrN8sxvOYVHR'], '7']], [[[[Zbroj(16, 9), [60162, 'AvnE'], 6901], 48315]]], [Zbroj(0, 17)], [Zbroj(14, 0)], [92721], [[[Zbroj(18, 13), [[[Zbroj(20, 6), Zbroj(6, 9)], 'K8WqH4Ry'], 'xvtzF']], 95372]], [[[[[Zbroj(11, 4), Zbroj(11, 2)]], Zbroj(12, 17)]]], ['ESodQJyp'], [['2b8rFJ1ANaCB0y', Zbroj(0, 20)]], [[Zbroj(6, 0), '7rgM', 'HlathZrDPBGsvO']], [[Zbroj(6, 14), [[[[['lBIUa3w1R']], Zbroj(6, 2)], Zbroj(18, 4)], 'f'], 'C2XpPhAN5yBMV7']], [[[Zbroj(0, 2), 'R2Al9']]], [['9DMPE']], [Zbroj(6, 15)], [['0R93HiK', [Zbroj(16, 15), [98143, ['aEWekmAqilg', [73160, [Zbroj(17, 0), [86146], Zbroj(9, 18)]]], 37972], 23428]]], [['A', [[Zbroj(15, 1), ['APn', [[[[[[2093, 20354]]], Zbroj(12, 18)], 13680]]], 66238]], Zbroj(3, 14)]], [['hOykPmdpwT38', [16046, Zbroj(12, 7), Zbroj(13, 12)]]], [[[Zbroj(12, 15), [Zbroj(16, 10), [15746, [Zbroj(11, 2), [Zbroj(2, 4), [[[Zbroj(10, 3), [[[[[[['nUPqkm0ZjdAEDci', ['8', [[16370], 11376]], Zbroj(19, 14)], 40723], 'ZuhYXj'], Zbroj(0, 20)]]]], 'PZlSQ7'], 75203], 61067]], 128]]], Zbroj(14, 17)]]], [[Zbroj(0, 6), Zbroj(15, 0)]], [[64622, ['Yh1sA3L', 'BuZw7t018Ld4Q5i']]], [Zbroj(14, 5)], [[8675, [Zbroj(9, 0), [[['sPh', Zbroj(19, 11)], Zbroj(0, 7)]]]]], [[[['gxNur', [69115, [Zbroj(8, 16)], Zbroj(10, 1)], 52811], Zbroj(17, 1)], Zbroj(17, 5)]], [[95352, Zbroj(11, 7), '0uAxJ']], [[[[Zbroj(18, 5), [Zbroj(5, 6), [Zbroj(9, 15), [46531, [[[Zbroj(16, 19), Zbroj(9, 10)]], 65299], Zbroj(7, 11)], Zbroj(1, 10)], Zbroj(1, 12)], Zbroj(6, 16)], 18030], 29661]], [[Zbroj(8, 4), ['fvTXDlk9H', [12594], 'D'], Zbroj(15, 4)]], [[Zbroj(2, 20), [Zbroj(10, 10), Zbroj(12, 10), 'FoIygJt3lH4bvr'], Zbroj(19, 17)]], [[[Zbroj(14, 19), [57526, [[[Zbroj(19, 17), [Zbroj(11, 14), [59205, ['BJ0vOPEVqNo', [['9bmWnwTBa8', Zbroj(4, 13), 32132]]], Zbroj(20, 9)]], Zbroj(2, 2)], Zbroj(12, 6)], '2P1'], Zbroj(19, 17)]], Zbroj(17, 11)]], [[21957, Zbroj(16, 15), Zbroj(15, 10)]], [[12791, [72348, 'gsmqRBZ']]], [[9627, [Zbroj(4, 9), ['SyaE3nfOI', [[Zbroj(1, 19), [Zbroj(15, 1), [Zbroj(0, 17), ['pl2mW0ZQ', [Zbroj(2, 4), Zbroj(20, 8)]], 32093], Zbroj(4, 13)], Zbroj(16, 2)]]]]]], [[[Zbroj(14, 16), [[44242, '3gBIL'], 'I']]]], [Zbroj(1, 18)], [['9xX7nwH0', ['GwAs4zLZOYg6D3k', [[[Zbroj(8, 7), [[Zbroj(10, 20), [Zbroj(14, 10), Zbroj(6, 0)], Zbroj(11, 10)]]]], 70216]], 'l3n1oATpPBmHu']], [[[33871], 'n3hmIbXyEpVt1c']], ['NB8YZpcsWH5'], [[[[Zbroj(15, 10), [[49083, [[Zbroj(13, 17), [Zbroj(12, 9), [[[35588, [Zbroj(10, 18), ''], 51336]], Zbroj(9, 6)], 89171], Zbroj(1, 4)]]], Zbroj(19, 17)], Zbroj(14, 6)]]]], [[Zbroj(17, 5), [Zbroj(13, 2), 73613]]], [[Zbroj(17, 0), [[[Zbroj(5, 20), 28930], Zbroj(19, 8)], 'YJq']]], [[['zYh35DVjgtIA4', [Zbroj(9, 3), [[['7b', Zbroj(8, 13)], Zbroj(10, 8)]]], 'F8UkphHu'], 37291]], [40329], [['QZDjmBVC', [Zbroj(19, 9), [61782, 'Rp9VLPguea', Zbroj(13, 9)]], Zbroj(0, 16)]], [[Zbroj(12, 0), [[[Zbroj(5, 2), 'zKesPQ6cxEM2', Zbroj(11, 17)]], 'IQ'], Zbroj(1, 15)]], [[[[[[Zbroj(3, 5), [Zbroj(20, 1), [Zbroj(8, 9), [[[['hM2y9E1rz7gb4d', [[[Zbroj(19, 3), [Zbroj(12, 9), ['DRPWC', [[61580, 'oNr857wckOlzP', Zbroj(4, 2)], Zbroj(12, 1)], 'WCbRZu67193Na']], Zbroj(0, 5)], 'mJDX3kyTj'], 'wR5d0PXY']]], Zbroj(11, 9)], 'W2zCI'], Zbroj(7, 16)]], 91077], Zbroj(7, 17)]], 35465], Zbroj(0, 12)]], [[[[[40920, ['0ZOQqNmoAYw', [['5Mh9G', [Zbroj(3, 16), [[[[[Zbroj(9, 2), [73731, [[20181, [[[Zbroj(11, 9), 'ZB']], Zbroj(20, 3)]], Zbroj(12, 8)], Zbroj(15, 9)], 42134]]], 'UKL'], Zbroj(20, 13)]], 34317]]]]]]]], [[['', [77880, [Zbroj(12, 0), Zbroj(2, 9), 60846]], Zbroj(9, 16)]]], [76191], [[Zbroj(15, 18), [1966, 'oGVgzsHpqTOwL', Zbroj(10, 20)], 73811]], [[Zbroj(0, 19), 'Fdwjhy8M', 52100]], [Zbroj(20, 0)], [[88903, 35030]], [['HV', [[[16706, [45642, [[[[54252, Zbroj(12, 19), 55822]]], 24105]], 'M8hFKtWPy40Q3'], 'Z9OPT8eo0gd2'], 'pymvU2LuOVC'], Zbroj(3, 20)]], [[Zbroj(5, 3)]], [[Zbroj(8, 8), [[83919, [[77905, [[[Zbroj(4, 17), [[Zbroj(7, 11), [53181, [[[Zbroj(3, 1), Zbroj(5, 18)], Zbroj(20, 7)], Zbroj(1, 6)]], Zbroj(6, 5)], 'VBp3rUR9K2']], Zbroj(13, 20)], 'MeIgaiCY9d'], 44649]]], Zbroj(6, 0)]]], [Zbroj(9, 4)], [[Zbroj(13, 0), [Zbroj(17, 14), [[Zbroj(13, 11), Zbroj(19, 16), Zbroj(18, 15)], Zbroj(14, 7)], Zbroj(19, 0)], Zbroj(13, 16)]], [10405], [[[[Zbroj(9, 17), [['Gu1mLSq', [87720, [['VX8H7OgUTRk23Z', [Zbroj(11, 10), [[Zbroj(13, 3), Zbroj(12, 5), 'sYkPFd']]], 44756], 9978], 88497], 'D03f'], 19103]]], Zbroj(6, 5)]], [['WLa0iM6yJThokj', [[Zbroj(11, 2), [54195, 96488, Zbroj(13, 7)]]]]], [[20052]], [['Jv']], [[[[87378, [['YqI']]], 't'], 63348]], [[[Zbroj(10, 9), [61828, [Zbroj(7, 2), [Zbroj(15, 7), [Zbroj(8, 11), ['jzvk2coL', ['K', [[Zbroj(1, 5), [15008, [''], Zbroj(15, 19)], 82696]]]], 68454]], Zbroj(13, 18)], Zbroj(17, 5)]]]], [['kju043hcq6', [50625, [Zbroj(14, 10), Zbroj(15, 2)], Zbroj(13, 20)], 'LPFqic4W9']], [['cXH2gSbNtFx', [68712, [Zbroj(18, 20), [Zbroj(20, 12), 'Q']], Zbroj(19, 19)], '3EJVBbu']], [[['cMZ2WqX', Zbroj(12, 8)], Zbroj(10, 5)]], [[Zbroj(8, 13), [Zbroj(20, 20), Zbroj(15, 5), Zbroj(3, 8)], Zbroj(3, 16)]], [[Zbroj(17, 17), 39195]], [[Zbroj(1, 17), [['bTu0Es', [Zbroj(10, 2), ['AeWDB9', Zbroj(6, 15)]], 'zm']]]], [23827], [[[34795, ['PByRdk6YxA9', Zbroj(14, 2)]]]], [[Zbroj(4, 12), [Zbroj(8, 12), [[Zbroj(0, 0), [Zbroj(12, 5), Zbroj(16, 11)]]], ''], 97555]], [[[36035], 'ZIPh2gHvBspi']], [[[21742, [['uyboOHnZk', [[[Zbroj(1, 9), [[Zbroj(6, 4), [[[65031, ['4pa'], Zbroj(8, 18)], Zbroj(3, 19)], 18688]], 38237], Zbroj(9, 19)], Zbroj(9, 12)]], '7xa']]]]], [6118], [[[Zbroj(2, 2)], Zbroj(11, 20)]], ['N2fKaZmbu7zg'], ['MSsU9xFNXQ2Bl'], [1862], [[Zbroj(8, 15), [[[['0TlQZjtKEGOI4w', [Zbroj(6, 16), ['cjrHTWguoNQ', ['4N5Gm', [Zbroj(16, 13), [['7sYX']]], Zbroj(10, 6)], 62461]]], 68455]]], Zbroj(12, 15)]], [Zbroj(4, 9)], [[[27462]]], [[Zbroj(0, 0), [Zbroj(3, 4), ['ai6Lt7boPk', [92952, Zbroj(9, 19), Zbroj(10, 12)], Zbroj(7, 4)]], Zbroj(9, 9)]], [['f', [Zbroj(4, 16), 32504, 12073], Zbroj(2, 9)]], [[[[34853, ['xgAFXcLfui', 1660], Zbroj(11, 14)], Zbroj(2, 20)], Zbroj(8, 3)]], [[[['', [Zbroj(14, 1), Zbroj(1, 19)]], 49796]]], [[Zbroj(1, 2)]], [[47455, ['Z8f3rjNp', ''], Zbroj(5, 19)]], [93437], [[[58041, [[19332, [[Zbroj(14, 18), [Zbroj(8, 20), ['7sgu4ym1', ['7VFs', 93422, Zbroj(12, 5)], Zbroj(1, 8)], 'MGyZiUJjoqL'], Zbroj(0, 12)]]], Zbroj(3, 4)], Zbroj(20, 20)], 15554]], [[['xMR9NAp3j', [[[Zbroj(13, 7), ['butkIKWU2Yqe6oL', [['Rih8dYQok09Zn', [[Zbroj(9, 0), [[[Zbroj(2, 17), [14843, [[Zbroj(16, 20), Zbroj(14, 4)], 'Orf0pgyXW4t']]]], '5']], Zbroj(5, 15)]], 'hNpdwA'], 'DgF5bTIS']]]], 'bm9eY3n'], 'E']], ['1scMFOY29'], [[Zbroj(18, 5), ['98EIJn', Zbroj(13, 10)]]], [['kvWxowT7', [Zbroj(15, 11), ['6u4pRhJLM', [55269, ['', [62060, [[Zbroj(17, 19), [[[Zbroj(6, 5)]], 'E9Sm'], Zbroj(7, 15)]], 45399], Zbroj(4, 3)], Zbroj(6, 5)]]]]], [['', Zbroj(7, 10)]], [[[Zbroj(12, 11), [Zbroj(4, 15), [76418, Zbroj(10, 8), Zbroj(19, 19)]]]]], [[Zbroj(3, 6), [46729, [1133, [[Zbroj(4, 19), [Zbroj(16, 6), ['FyDRQ7vPGS', [51761, 51335, 40249]]]], 'pNvhWtlPgY'], 'xUlbCSjL1NM4R'], Zbroj(4, 11)], 'O6SVGe2UoP7Ydct']]]
- podaci2 = [[2, [2, [2]], [2], [[[[[2]]]]]]]
- found = False
- def pocetak(podaci):
- global found
- largest = 0
- for e in podaci:
- found = False
- output = traverse(e, 1)
- if found and output > largest:
- largest = output
- return largest
- # n je dubina
- def traverse(element, n):
- global found
- depths = []
- for e in element:
- if isinstance(e, list):
- depths += [traverse(e, n+1)]
- if isinstance(e, Zbroj):
- if e.vrijednost() == 9000:
- found = True
- if len(depths) > 0:
- return max(depths)
- else:
- return n
- print(pocetak(podaci))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement