Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import time
- heights="""
- 2199943210
- 3987894921
- 9856789892
- 8767896789
- 9899965678"""
- heights = heights.split("\n"); heights.pop(0)
- htsArray = np.array(heights)[:, np.newaxis]
- leastHeights = []
- y=0 # this will all life be 0
- for x in range(len(htsArray)): # i'm using x & y coords to denote array for readablityi
- # print(htsArray[x][y], type(htsArray[x][y]))
- for y2,a in enumerate(htsArray[x][y]):
- # print(y2, a)
- minHtOld = a+str(x)+str(y2) # x & y2 are coordinates of a
- while True:
- a = minHtOld[0]; x = int(minHtOld[1]); y2 = int(minHtOld[2])
- print(a, x, y2,"restarted while true")
- # print('came up')
- # first 4 if conditions check for corner coords, then next 4 check sides coords, then final else is middle oprtion
- if x == 0 and y2 == 0: # means top left corner
- print('came in top left corner')
- if htsArray[1][y][0] > htsArray[0][y][1]: # if botom no > than right no
- smaller = htsArray[0][y][1] + "01"
- else:
- smaller = htsArray[1][y][0] + "10"
- if a > smaller:
- minHtNew = smaller
- else:
- minHtNew = a + "00"
- if minHtNew[0] == minHtOld[0]:
- print("This be final answer from trc:", minHtNew)
- leastHeights.append(minHtOld[0])
- break
- minHtOld = minHtNew
- # print(minHtOld, minHtNew)
- elif x == 0 and y2+1 == len(htsArray[0][y]): # means top right corner
- print("came in trc")
- elif x+1 == len(htsArray) and y2 == 0: # means bottom left corner
- print("Came in blc")
- elif x+1 == len(htsArray) and y2+1 == len(htsArray[0][y]): # means bottom right corner
- print("came in brc")
- elif x == 0: # means top row excluding corners
- print("came in top row")
- if htsArray[0][y][y2-1] > htsArray[0][y][y2+1]:
- print("came in left > right")
- smaller = htsArray[0][y][y2+1] + "0" + str(y2+1)
- else:
- print("came in right > left")
- smaller = htsArray[0][y][y2-1] + "0" + str(y2-1)
- if smaller[0] > htsArray[1][y][y2]:
- print("came in smaller > bottom")
- smaller = htsArray[1][y][y2] + "1" + str(y2)
- if smaller[0] >= a:
- print(f"came in smaller {smaller[0]} > current {a}")
- smaller = minHtOld
- minHtNew = smaller
- print("These are new & old & smaller", minHtNew, minHtOld, smaller)
- if minHtNew[0] == minHtOld[0]:
- print("This be final answer from top row:", minHtNew)
- leastHeights.append(int(minHtOld[0]))
- break
- minHtOld = minHtNew
- elif y2 == 0:
- print("came in left column")
- elif y2+1 == len(htsArray[x][0]):
- print("came in right column")
- elif x+1 == len(htsArray):
- print("came in bottom row")
- else:
- print("came in middle section")
- time.sleep(1)
- time.sleep(1); print(">>>>>>>>> Changing y2 >>>>>>>>>>")
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement