ãã®ä»ãã©ã³ãã ã«ããã·ãã¯ã¹ã®æ°åãä½åãé¸ã¶é¢æ°ã¨ããå®ãããããã§æ½é¸çµæã®çªå·ãã³ãã¼ããã¨å
¨è§æ°åã¨ãæ··ããã®ã§æå½¢ããé¢æ°ã¨ããã
#!/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)
ã¨ããããããã§ããããã