# redmond python problem

Feb 21st, 2018
130
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def check(t, depth, myrange):
2.     #print('checking ' + str(t))
3.     #print (' depth = ' + str(depth))
4.     if t is None:
5.         return True
6.     left_range_list = []
7.     if not check(t[0],depth+1,left_range_list):
8.         return False
9.     right_range_list = []
10.     if not check(t[2],depth+1,right_range_list):
11.         return False
12.     myrange.append([t[1],t[1]])
13.     for i in range(max(len(left_range_list),len(right_range_list))):
14.         if i < len(left_range_list):
15.             left_range = left_range_list[i]
16.         else:
17.             left_range = None
18.         if i < len(right_range_list):
19.             right_range = right_range_list[i]
20.         else:
21.             right_range = None
22.         if left_range is None:
23.             myrange.append(right_range)
24.         elif right_range is None:
25.             myrange.append(left_range)
26.         else:
27.             range_evenness = (i+depth+1)%2
28.             #print('merging ' + str(left_range) + ' with ' + str(right_range) + ' at ' + str(range_evenness) + ' evenness')
29.             if left_range[1] == right_range[0] or \
30.                (left_range[1] > right_range[0]) != (range_evenness == 0):
31.                 #print('left and right in wrong order')
32.                 return False
33.             #print('merge ok')
34.             myrange.append([left_range[0],right_range[1]])
35.     return (depth % 2 != t[1] % 2)
36.
37. ranges = []
38. print('check 1 = ' + str(check([[[None,9,None],2,[None,7,None]],1,[[None,5,None],4,[None,3,None]]],0,ranges)))
39. print('ranges = ' + str(ranges))
40. ranges = []
41. print('check 2 = ' + str(check([[[None,9,None],2,[None,5,None]],1,[[None,7,None],4,[None,3,None]]],0,ranges)))
42. print('ranges = ' + str(ranges))
43. ranges = []
44. print('check 3 = ' + str(check([[[None,9,None],2,[None,7,None]],1,[[None,5,None],4,None]],0,ranges)))
45. print('ranges = ' + str(ranges))
46. ranges = []
47. print('check 4 = ' + str(check([[[None,9,None],2,[None,7,None]],1,[[None,5,None],5,[None,3,None]]],0,ranges)))
48. print('ranges = ' + str(ranges))
RAW Paste Data