]> Skullheadx's Git Forge - CCC.git/commitdiff
2021 S4 attempt 1
authorSkullheadx <admonty1@gmail.com>
Wed, 8 Feb 2023 21:11:48 +0000 (16:11 -0500)
committerSkullheadx <admonty1@gmail.com>
Wed, 8 Feb 2023 21:11:48 +0000 (16:11 -0500)
Main/Python/2019/S3.py [new file with mode: 0644]
Main/Python/2021/.idea/.gitignore [new file with mode: 0644]
Main/Python/2021/S4.py [new file with mode: 0644]

diff --git a/Main/Python/2019/S3.py b/Main/Python/2019/S3.py
new file mode 100644 (file)
index 0000000..19b23ff
--- /dev/null
@@ -0,0 +1,152 @@
+from queue import Queue
+from random import randint
+
+
+def find_a(b, c):
+       return b - c - b
+
+
+def find_b(a, c):
+       return a + (c - a) // 2
+
+
+def find_c(a, b):
+       return b + b - a
+
+
+square = []
+
+for i in range(3):
+       square.append(input().split())
+
+for row in square:
+       for i in range(len(row)):
+               if row[i].isdigit():
+                       row[i] = int(row[i])
+
+def fill_unknown(square):
+       for row in square:
+               a, b, c = row
+               known = list(map(type, row)).count(int)
+
+               if known == 2:
+                       if isinstance(a, str):
+                               a = find_a(b, c)
+                               row[0] = a
+                       elif isinstance(b, str):
+                               b = find_b(a, c)
+                               row[1] = b
+                       elif isinstance(c, str):
+                               c = find_c(a, b)
+                               row[2] = c
+
+       for i in range(3):
+               a, b, c = square[0][i], square[1][i], square[2][i]
+               known = list(map(type, [a, b, c])).count(int)
+               if known == 2:
+                       if isinstance(a, str):
+                               a = find_a(b, c)
+                               square[0][i] = a
+                       elif isinstance(b, str):
+                               b = find_b(a, c)
+                               square[1][i] = b
+                       elif isinstance(c, str):
+                               c = find_c(a, b)
+                               square[2][i] = c
+       return square
+
+
+def is_good(square):
+       for row in square:
+               a, b, c = row
+               if (b - a) * 2 + a != c:
+                       return False
+       for i in range(3):
+               a, b, c = square[0][i], square[1][i], square[2][i]
+               if (b - a) * 2 + a != c:
+                       return False
+       return True
+
+
+def deepcopy(square):
+       return [row[:] for row in square]
+
+def fill_random(square):
+       for i in range(3):
+               for j in range(3):
+                       if isinstance(square[i][j], str):
+                               square[i][j] = randint(-1000000000, 1000000000)
+                               square = fill_unknown(square)
+       return square
+
+square = fill_unknown(square)
+
+while True:
+       s = deepcopy(square)
+       s = fill_random(s)
+       if is_good(s):
+               for row in s:
+                       print(*row)
+               break
+# q = Queue()
+# q.put(square)
+#
+# while not q.empty():
+#      current = q.get()
+#      if is_good(current):
+#              print(current)
+#              break
+#
+#      row = current[0]
+#      a, b, c = row
+#      known = list(map(type, row)).count(int)
+#
+#      if known == 1:
+#              if isinstance(a, int):
+#                      s, e = -1000000000, 1000000000
+#                      s = max(s, current[0][0])
+#                      e = min(e, current[1][[1]])
+#                      x = deepcopy(current)
+#                      x[0][0] = randint(s, e)
+#                      x[0][2] = find_c(x[0][0], x[0][1])
+#                      q.put(x)
+#
+#                      s, e = -1000000000, 1000000000
+#                      s = max(s, current[0][0])
+#                      e = min(e, current[1][[2]])
+#                      x = deepcopy(current)
+#                      x[0][2] = randint(s, e)
+#                      x[0][1] = find_b(x[0][0], x[0][2])
+#                      q.put(x)
+#              elif isinstance(b, int):
+#                      s, e = -1000000000, 1000000000
+#                      e = min(e, current[0][1])
+#                      x = deepcopy(current)
+#                      x[0][0] = randint(s, e)
+#                      x[0][2] = find_c(x[0][0], x[0][1])
+#                      q.put(x)
+#
+#                      s, e = -1000000000, 1000000000
+#                      s = max(s, current[0][1])
+#                      e = min(e, current[1][[2]])
+#                      x = deepcopy(current)
+#                      x[0][2] = randint(s, e)
+#                      x[0][0] = find_a(x[0][1], x[0][2])
+#                      q.put(x)
+#              elif isinstance(c, int):
+#                      s, e = -1000000000, 1000000000
+#                      e = min(e, current[0][2])
+#                      x = deepcopy(current)
+#                      x[0][1] = randint(s, e)
+#                      x[0][0] = find_a(x[0][1], x[0][2])
+#                      q.put(x)
+#
+#                      s, e = -1000000000, 1000000000
+#                      e = min(e, current[1][[1]])
+#                      x = deepcopy(current)
+#                      x[0][1] = randint(s, e)
+#
+#                      q.put(x)
+#
+#      elif known == 0:
+#              pass
diff --git a/Main/Python/2021/.idea/.gitignore b/Main/Python/2021/.idea/.gitignore
new file mode 100644 (file)
index 0000000..13566b8
--- /dev/null
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/Main/Python/2021/S4.py b/Main/Python/2021/S4.py
new file mode 100644 (file)
index 0000000..dec7ef2
--- /dev/null
@@ -0,0 +1,53 @@
+from queue import Queue
+"""
+start at station 1 then go to station N
+
+There are W one way walkways between stations
+A, B = stations connected by walkway
+time = 1 min
+
+Every day (D is total days), station X and Y swap
+
+
+
+"""
+
+
+def swap(i, j):
+       stations[i], stations[j] = stations[j], stations[i]
+
+
+N, W, D = tuple(map(int, input().split()))
+walkways = dict()
+for i in range(W):
+       A, B = tuple(map(int, input().split()))
+       walkways[A] = walkways.get(A, list()) + [B]
+
+stations = list(map(int, input().split()))
+for i in range(D):
+       X, Y = tuple(map(int, input().split()))
+       swap(X-1, Y-1)
+
+       q = Queue()
+       visited = set()
+
+       q.put((stations[0], 0))
+       if stations[0] in walkways:
+               for neighbor in walkways[stations[0]]:
+                       q.put((neighbor, 1))
+
+       while not q.empty():
+               curr, time = q.get()
+               if curr in visited:
+                       continue
+               else:
+                       visited.add(curr)
+               if curr == N:
+                       print(time)
+                       break
+               for neighbor in walkways.get(curr, list()):
+                       if neighbor not in visited:
+                               q.put((neighbor, time + 1))
+               q.put((stations[stations.index(curr) + 1], time + 1))
+
+