Skip to content

Instantly share code, notes, and snippets.

@musabkilic
Last active June 20, 2020 15:48
Show Gist options
  • Select an option

  • Save musabkilic/7d2291e47a14108fceb46831107f93f0 to your computer and use it in GitHub Desktop.

Select an option

Save musabkilic/7d2291e47a14108fceb46831107f93f0 to your computer and use it in GitHub Desktop.
# Musab K.
from string import ascii_letters
from itertools import combinations
nums = [list(sorted([int(y) for y in x.split(" ")])) for x in open("numlist.txt", "r").read().replace("\n\n", "\n").split("\n")[:-1]]
all_nums = []
for l in nums:
for n in l:
if not n in all_nums:
all_nums.append(n)
all_nums.sort()
P = []
for i in range(len(all_nums)):
n = all_nums[i]
p = []
inc = 0
for l in nums:
if n in l:
inc += 1
for a in l:
if not a in p:
p.append(a)
for c in combinations(p, 3):
c = list(sorted(c))
if not c in nums:
print("ERR 1")
exit()
nums.remove(c)
if inc > 0:
if inc != (len(p) - 1) * (len(p) - 2) / 2:
print("ERR 2")
exit()
P.append(p)
for i in range(len(all_nums)):
n = all_nums[i]
A = []
for j, p in enumerate(P):
if n in p or -n in p:
A.append(p)
if len(A) != 2:
print("ERR 3")
exit()
for p in P:
print(p)
print(len(all_nums)//2, ">", len(P)*2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment