Apr-03-2023, 02:55 PM
(This post was last modified: Apr-03-2023, 02:55 PM by deanhystad.)
Is the problem that you have a bunch of random lists and you are trying to find lists that match the start pattern, or are you trying to generate random lists that match the start problem. These are totally different problems and there are totally different approaches for solving.
This is my solution to the first problem (finding lists that match start)
This is my solution to the first problem (finding lists that match start)
start_list = [1, 2] MAX = 100 # Since I don't have a bunch of random lists to test, I will make some and see how long it takes to find a match. for attempt in range(1, 10000000000000): random_list = [randint(1, MAX) for _ in range(4)] if random_list[:2] == start_list: print(attempt, ":", random_list) breakThis is my approach to solving the second problem (making list len(4) that starts with starting pattern.
start_list = [1, 2] MAX = 100 random_list = start_list + [randint(1, MAX) for _ in range(2)] print(random_list)