Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. def weakSidon(sequence_length):
  2. """Finds a weak Sidon sequence (a sequence (a_i) of integers where a_i + a_j for i < j are all unique) of the necessary length."""
  3. sequence = [1]
  4. sums = []
  5. while len(sequence) < sequence_length:
  6. test_integer = sequence[-1] + 1
  7. test_sums = list(map(lambda x: test_integer + x, sequence))
  8. while any(x in list(test_sums) for x in sums):
  9. test_integer = test_integer + 1
  10. test_sums = list(map(lambda x: test_integer + x, sequence))
  11. sequence.append(test_integer)
  12. sums = sums + test_sums
  13. return sequence
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement