brunch

You can make anything
by writing

C.S.Lewis

by 유윤식 Jul 23. 2024

Python : 1 / 8145060 (3)

#로또 #당첨번호위치 #자동원리 #당첨기원

이전 포스팅에서 로또 당첨번호 히스토리 정보를 읽어오고 내용을 확인했다.


1회차 ~ 1129회차 까지 모두 가져왔다.


간단하게 1129회차 당첨번호는 모든 조합 내에서 몇번째에 위치하는걸까?


그리고 모든 당첨번호들은 몇번째에 위치했으며 혹시 어떤 패턴이 있기는 한걸까? (당연히 패턴은 없다...)


나는 그럼 몇번째 위치를 선택해서 5개의 게임에서 1등에 당첨될 수 있을까? (매우 어렵다...)


하나씩 풀어보면,


첫번째의 정답은 : (6493492, 1129) 즉, 1129회차 로또 당첨번호는 6,493,492 번째에 위치한다.

이걸 어떻게 알 수 있을까?


이전 포스팅의 결과는 제외하고,


import numpy as np


# all_combinations # 총 조합 개수: 8145060, 모든 조합의 리스트

# history_data # 1129회차 까지의 1등 당첨번호 리스트


history_data = df_final.select(pl.col('당첨번호')).to_numpy()

history_data = history_data.reshape(-1, len(history_data))[0]

history_data = [i[:-1] for i in history_data] # 6자리 당첨번호만 추출


history_data_list = [tuple(row) for row in history_data]

history_data_set = set(history_data_list)


matching_indices = []

for i, row in enumerate(all_combinations):

    if tuple(row) in history_data_set:

        matching_index_in_history = history_data_list.index(tuple(row)) + 1

        matching_indices.append((i, matching_index_in_history))


print("일치하는 배열의 위치 (all_combinations_idx, history_data_idx):", sorted(matching_indices, key=lambda x: x[1]))



일다 여기까지 처음 로또의 당첨번호는 3,932,248번째에서 등장한다.


대략 느낌이 오는데...


패턴은 없고, 다음 당첨번호의 위치는 물론 알 수 없다!!


다음번에는 해당 숫자들의 분포와 같은 당첨번호가 등장할 수 있는 확률 등에 대해서 알아보면 좋을 것 같다.


아직 포기하긴 이르다!

작가의 이전글 Python : 1 / 8145060 (2)
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari