First try, fails for more than 6 numbers
This commit is contained in:
parent
790d84b83f
commit
adfa2031f7
1 changed files with 57 additions and 0 deletions
57
generator.py
Executable file
57
generator.py
Executable file
|
@ -0,0 +1,57 @@
|
|||
#! env python3
|
||||
|
||||
from random import randrange
|
||||
|
||||
def existing_combination(number, reds, combinations):
|
||||
for red in reds:
|
||||
if (red + number) in combinations:
|
||||
return True
|
||||
return False
|
||||
|
||||
def update_combinations(number, reds, combinations):
|
||||
for red in reds:
|
||||
combinations.append(red + number)
|
||||
return combinations
|
||||
|
||||
debug = True
|
||||
red_size = 6
|
||||
blue_size = red_size
|
||||
reds = []
|
||||
blues = []
|
||||
combinations = []
|
||||
|
||||
for i in range(red_size):
|
||||
new_number = randrange(99)
|
||||
|
||||
while new_number in reds:
|
||||
new_number = randrange(99)
|
||||
|
||||
reds.append(new_number)
|
||||
|
||||
if debug:
|
||||
print(f'red #{i+1} found')
|
||||
|
||||
reds.sort()
|
||||
if debug:
|
||||
print(reds)
|
||||
|
||||
for i in range(blue_size):
|
||||
new_number = randrange(99)
|
||||
|
||||
while new_number in reds or new_number in blues or existing_combination(new_number, reds, combinations):
|
||||
new_number = randrange(99)
|
||||
|
||||
blues.append(new_number)
|
||||
combinations = update_combinations(new_number, reds, combinations)
|
||||
|
||||
if debug:
|
||||
print(f'blue #{i+1} found')
|
||||
|
||||
blues.sort()
|
||||
combinations.sort()
|
||||
|
||||
if debug:
|
||||
print(blues)
|
||||
print(combinations)
|
||||
|
||||
# vim: set sw=2 ts=2 et:
|
Loading…
Reference in a new issue