Skip to content

Instantly share code, notes, and snippets.

@ALiwoto
Created October 19, 2022 18:32
Show Gist options
  • Save ALiwoto/f7ce50ec0d023bc5143d631aadce054a to your computer and use it in GitHub Desktop.
Save ALiwoto/f7ce50ec0d023bc5143d631aadce054a to your computer and use it in GitHub Desktop.
itertools.combinations example code
import typing
import itertools
MAX_POSITION = 6
MIN_NUM = 1
MAX_NUM = 12
temp_selected_nums: typing.List[int] = []
def is_multiple(a, b):
return a/b == a//b or b/a == b//a
def check_list(the_list: typing.List[int]):
for i in range(len(the_list)):
for j in range(len(the_list)):
if i == j: continue
if is_multiple(temp_selected_nums[i], temp_selected_nums[j]):
return False
return True
stuff = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
for subset in itertools.combinations(stuff, 6):
temp_selected_nums = []
for i in subset:
temp_selected_nums.append(i)
if check_list(temp_selected_nums):
print(temp_selected_nums)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment