Ver Fonte

day 5 part 2

Phil há 5 anos atrás
pai
commit
36c44b7ad4
1 ficheiros alterados com 31 adições e 24 exclusões
  1. 31 24
      5/main.py

+ 31 - 24
5/main.py

@@ -6,44 +6,51 @@ def getRow(code):
     high = 127
     low = 0
     for c in code:
-        #print('Row Char: '+c)
+        print('Row Char: '+c)
         if c == 'F':
-            high -=int( (high - low) / 2)
-            #print('high: '+str(high))
+            high -=int( (high - low + 1) / 2)
         else:
-            low +=int( (high - low) / 2)
-            #print('low: '+str(low))
-    if code[-1] == 'F':
-        return high
-    else:
-        return low
+            low +=int( (high - low + 1 ) / 2)
+    print('low: ' + str(low) + ' high: ' + str(high))
+    return low
 
 def getSeat(code):
     high = 7
     low = 0
     for c in code:
-        #print('Row Char: '+c)
-        if c == 'R':
-            high -=int( (high - low) / 2)
-            #print('high: '+str(high))
+        print('Row Char: '+c)
+        if c == 'L':
+            high -=int( (high - low +1) / 2)
         else:
-            low +=int( (high - low) / 2)
-            #print('low: '+str(low))
-    if code[-1] == 'F':
-        return high
-    else:
-        return low
+            low +=int( (high - low + 1) / 2)
+    print('low: ' + str(low) + ' high: ' + str(high))
+    return low
 
 
 
 maxSeat = 0
+seats = []
+#passes = ['FBFBBFFRLR','BFFFBBFRRR','FFFBBBFRRR','BBFFBBFRLL']
 for p in passes:
     row = getRow(p[:7])
     column = getSeat(p[7:10])
-    seatID = row * 8 + column
-    #print('row: '+str(row))
-    #print('col: '+str(column))
-    #print('seat: '+str(seatID))
+    seatID = (row * 8) + column
+    seats.append(seatID)
+    print(p)
+    print('row: '+str(row))
+    print('col: '+str(column))
+    print('seat: '+str(seatID))
     if seatID > maxSeat:
         maxSeat = seatID
-print(str(maxSeat))
+
+last = 0
+preLast = 0
+seats = sorted(set(seats), key = lambda ele: seats.count(ele))
+#seats.sort()
+for s in seats:
+    print(str(last) + ' vs ' + str(s))
+    if s - 1 != last and s == last + 2:
+        print('hole between ' + str(s) + ' and ' + str(last))
+    preLast = last
+    last = int(s)
+#print(str(maxSeat))