Advertisement
Guest User

Untitled

a guest
Dec 9th, 2021
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.45 KB | None | 0 0
  1. import numpy as np
  2. import time
  3.  
  4. heights="""
  5. 2199943210
  6. 3987894921
  7. 9856789892
  8. 8767896789
  9. 9899965678"""
  10.  
  11. heights = heights.split("\n"); heights.pop(0)
  12.  
  13. htsArray = np.array(heights)[:, np.newaxis]
  14. leastHeights = []
  15.  
  16. y=0 # this will all life be 0
  17. for x in range(len(htsArray)): # i'm using x & y coords to denote array for readablityi
  18.     # print(htsArray[x][y], type(htsArray[x][y]))
  19.     for y2,a in enumerate(htsArray[x][y]):
  20.         # print(y2, a)
  21.         minHtOld = a+str(x)+str(y2) # x & y2 are coordinates of a
  22.         while True:
  23.             a = minHtOld[0]; x = int(minHtOld[1]); y2 = int(minHtOld[2])
  24.             print(a, x, y2,"restarted while true")
  25.             # print('came up')
  26.             # first 4 if conditions check for corner coords, then next 4 check sides coords, then final else is middle oprtion
  27.             if x == 0 and y2 == 0: # means top left corner
  28.                 print('came in top left corner')
  29.                 if htsArray[1][y][0] > htsArray[0][y][1]: # if botom no > than right no
  30.                     smaller = htsArray[0][y][1] + "01"
  31.                 else:
  32.                     smaller = htsArray[1][y][0] + "10"
  33.                 if a > smaller:
  34.                     minHtNew = smaller
  35.                 else:
  36.                     minHtNew = a + "00"
  37.                 if minHtNew[0] == minHtOld[0]:
  38.                     print("This be final answer from trc:", minHtNew)
  39.                     leastHeights.append(minHtOld[0])
  40.                     break
  41.                 minHtOld = minHtNew
  42.                 # print(minHtOld, minHtNew)
  43.             elif x == 0 and y2+1 == len(htsArray[0][y]): # means top right corner
  44.                 print("came in trc")
  45.             elif x+1 == len(htsArray) and y2 == 0: # means bottom left corner
  46.                 print("Came in blc")
  47.             elif x+1 == len(htsArray) and y2+1 == len(htsArray[0][y]): # means bottom right corner
  48.                 print("came in brc")
  49.             elif x == 0: # means top row excluding corners
  50.                 print("came in top row")            
  51.                 if htsArray[0][y][y2-1] > htsArray[0][y][y2+1]:
  52.                     print("came in left > right")
  53.                     smaller = htsArray[0][y][y2+1] + "0" + str(y2+1)
  54.                 else:
  55.                     print("came in right > left")
  56.                     smaller = htsArray[0][y][y2-1] + "0" + str(y2-1)
  57.                 if smaller[0] > htsArray[1][y][y2]:
  58.                     print("came in smaller > bottom")
  59.                     smaller = htsArray[1][y][y2] + "1" + str(y2)
  60.                 if smaller[0] >= a:
  61.                     print(f"came in smaller {smaller[0]} > current {a}")
  62.                     smaller = minHtOld
  63.                 minHtNew = smaller
  64.                 print("These are new & old & smaller", minHtNew, minHtOld, smaller)
  65.                 if minHtNew[0] == minHtOld[0]:
  66.                     print("This be final answer from top row:", minHtNew)
  67.                     leastHeights.append(int(minHtOld[0]))
  68.                     break
  69.                 minHtOld = minHtNew
  70.             elif y2 == 0:
  71.                 print("came in left column")
  72.             elif y2+1 == len(htsArray[x][0]):
  73.                 print("came in right column")
  74.             elif x+1 == len(htsArray):
  75.                 print("came in bottom row")
  76.             else:
  77.                 print("came in middle section")
  78.             time.sleep(1)
  79.         time.sleep(1); print(">>>>>>>>> Changing y2 >>>>>>>>>>")
  80.     break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement