Skip to content

Instantly share code, notes, and snippets.

@fhuszar
Last active March 26, 2025 10:12
Show Gist options
  • Save fhuszar/9027c1ba8d3d88eeebe17fd86f13fd63 to your computer and use it in GitHub Desktop.
Save fhuszar/9027c1ba8d3d88eeebe17fd86f13fd63 to your computer and use it in GitHub Desktop.
import random
answer = True
maxint = 1000
numrandom = 10000
books = list(set([random.randint(1, maxint) for _ in range(numrandom)]))
if answer:
#a random set of integers will be a positive example with a very high probability.
selected_books = books
else:
selected_books = []
sums = set()
for i, book in enumerate(books):
violation = False
for book2 in selected_books:
if book+book2 in sums:
violation = True
if violation:
continue
else:
for book2 in selected_books:
sums.add(book + book2)
selected_books.append(book)
print(' '.join([str(i) for i in selected_books]))
sums = set()
found = False
for i in range(len(selected_books)):
for j in range(i+1, len(selected_books)):
if (selected_books[i] + selected_books[j]) in sums:
found=True
else:
sums.add(selected_books[i] + selected_books[j])
if found:
print('YES')
else:
print('NO')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment