何個かロト6を買った時に抽選結果番号を確認するのが面倒だからPythonでスクリプト書いてみた。

その他、ランダムにロトシックスの数字を何個か選ぶ関数とか、宝くじネットで抽選結果の番号をコピーすると全角数字とか混じるので成形する関数とかも。

```#!/usr/bin/env python
# *-# -*- coding: utf-8 -*-

import re
import random

def choice_loto_six_number():
#ランダムにロト6の数字を選ぶ
return sorted(random.sample(range(1, 43 + 1), 6))

def choice_several_loto_six(num):
#ランダムにロト6の数字を何口か選ぶ
return [choice_loto_six_number() for i in range(num)]

def get_bingo_num(list_of_chosen_num, num_of_result):
"""
>>> get_bingo_num(['01', '02', '03', '04', '05', '06'], '05')
'05'
"""
for num in list_of_chosen_num:
if num.count(num_of_result):
return num
return None

def get_list_of_bingo_num(list_of_chosen_num, list_of_result_num):
"""
get_list_of_bingo_num(['01', '02', '03', '04', '05', '06'], ['01', '06', '12', '13', '14', '15', '02'])
['01', '06', '(02)']
"""
check_num_arr = []
for i, bingo_num in enumerate(list_of_result_num):
check_num = get_bingo_num(list_of_chosen_num, bingo_num)
if not check_num == None:
if i == 6:
check_num = "(%s)" % check_num
else:
list_of_chosen_num.sort()
check_num_arr.append(check_num)
return check_num_arr

def conv_int_to_str_for_chosen_num(list_of_chosen_num):
"""
>>> conv_int_to_str_for_chosen_num([2, 8, 11, 21, 31, 34])
['02', '08', '11', '21', '31', '34']
"""
chenge_num_arr = []
for num in list_of_chosen_num:
num = str(num)
if len(num) == 1:
num = "0%s" % num
chenge_num_arr.append(num)
return chenge_num_arr

def conv_result_str_to_list(result_str):
"""
宝くじネットで抽選結果の番号をコピーすると全角スペースとか混じるので成形してリストに
http://www.takarakujinet.co.jp/loto6/

>>> conv_result_str_to_list("01　04　19　28　34　40　(14) ")
['01', '04', '19', '28', '34', '40', '14']
"""
s = re.sub(r"\D", r"\t", result_str)
return [num for num in s.split('\t') if num != ""]

def main(chosen_num_multi_arr, list_of_result_num):
"""
>>> chosen_num_multi_arr = [['01', '02', '03', '04', '05', '06'],['07', '08', '09', '10', '11', '12'],['13', '14', '15', '16', '17', '18']]
>>>print main(chosen_num_multi_arr, ['01', '04', '06', '28', '34', '40', '14'])
['01', '02', '03', '04', '05', '06']
Bingo!=>['01', '04', '06']
['07', '08', '09', '10', '11', '12']
=>[]
['13', '14', '15', '16', '17', '18']
=>['(14)']
"""
bingo_arr = []
for arr in chosen_num_multi_arr:
list_of_chosen_num = conv_int_to_str_for_chosen_num(arr)
check_arr = get_list_of_bingo_num(list_of_chosen_num,
list_of_result_num)
bonus_count = 3 if not "".join(check_arr).count("(") else 4
bingo_flg = "\tBingo!" if bonus_count <= len(check_arr) else ""
bingo_arr.append("%s\n%s=>%s" %(arr, bingo_flg, check_arr))
return "\n".join(bingo_arr)

if __name__ == '__main__':
chosen_num_multi_arr = [
['01', '02', '03', '04', '05', '06'],
['07', '08', '09', '10', '11', '12'],
['13', '14', '15', '16', '17', '18'],
]

result_str = "01　04　19　28　34　40　(14) "
list_of_result_num = conv_result_str_to_list(result_str)

print main(chosen_num_multi_arr, list_of_result_num)
```

とりあえずこれでいいかしら