import os,sys
import numpy as np

prize_table = [
  ['1st', 21531600],
  ['2nd', 885990],
  ['3rd', 157500],
  ['4th', 9600],
  ['5th', 640],
  ['6th', 320],
  ['7th', 40],
]

def prize_matching(all_drawn_number, user_entry_nums):
  # initialize to default output
  prize = ['',0]

  # all_drawn_number = ([1,2,3,4,...],7)
  [drawn_numbers, extra_number] = all_drawn_number
  # drawn_numbers = [1,2,3,4,...]
  # extra_number = 7

  # match drawn number
  matched_number = 0
  # user_entry_nums = [1,2,3,4,5,6]
  for u_num in user_entry_nums:
    # 1st loop u_num = 1
    # 2nd loop u_num = 2

    # drawn_numbers = [1,2,3,4,5,6]
    for drawn_number in drawn_numbers:
    # 1st loop drawn_number = 1
    # 2nd loop drawn_number = 2

      if (drawn_number == u_num):
        matched_number = matched_number + 1
        break


  matched_extra_number = 0
  # user_entry_nums = [1,2,3,4,5,6]
  for user_num in user_entry_nums:
    # 1st loop user_num = 1
    # 2nd loop user_num = 2
    if (user_num == extra_number):
      matched_extra_number = matched_extra_number + 1
      break

  # matched_number = n
  # matched_extra_number = n

  # refer to HKJC https://bet.hkjc.com/marksix/userinfo.aspx?lang=en&file=prize_entitlement.asp
  if (matched_number == 6):
    # first_prize = True
    prize = prize_table[0]
    # prize = ['1st', 21531600]
  elif (matched_number == 5 and matched_extra_number == 1):
    # second_prize = True
    prize = prize_table[1]
    # prize = ['2nd', nnnnn]
  elif (matched_number == 5):
    # third_prize = True
    prize = prize_table[2]
  elif (matched_number == 4 and matched_extra_number == 1):
    # forth_prize = True
    prize = prize_table[3]
  elif (matched_number == 4):
    # fifth_prize = True
    prize = prize_table[4]
  elif (matched_number == 3 and matched_extra_number == 1):
    # sixth_prize = True
    prize = prize_table[5]
  elif (matched_number == 3):
    # seventh_prize = True
    prize = prize_table[6]
  else:
    pass
  return prize

def print_output(prize_result, user_entry_nums):
  # prize_result = ['1st', 21531600]
  # user_entry_nums = [1,2,3,4,5,6]
  print("Numbers of your entry: ", user_entry_nums)

  # str(prize_result[0]) = '1st'
  # str(prize_result[1]) = '21531600'
  print("Output prize = " + str(prize_result[0]) + " = $" + str(prize_result[1]))
  pass

# number of entry
# Numbers of your entry: [14, 21, 25, 34, 37, 41]
# ask user for numbers
print("please enter number of your choice:")
user_entry = eval(input())
# [user_entry] = [1,2,3,4,5,6]
print('Number of your entry: ', user_entry)
# user_entry[0]
# user_entry[1]
# user_entry[2]
# user_entry[3]

# NOTE: check if number of user entered is not equal to 6
if (len(user_entry) != 6):
  print('user entered numbers should be exactly 6')
  print('quitting ... ')
  sys.exit()

# NOTE: check if each number within range
for user_num in user_entry:
  if (user_num < 1 or user_num > 49):
    print('user entered number should be within 1 to 49')
    print('quitting ... ')
    sys.exit()

# Number of draw
# Numbers of draw: ([21, 25, 34, 37, 41, 46], 14)

# init seed randomizer
np.random.seed(21800000)

# init empty slot for number
temp_numbers = np.arange(0, 7, 1, dtype=int)

# drawn 7 numbers
# [1,2,3,4,5,6,7]
temp_numbers = np.random.choice(range(1,49), 7)

# the first 6 number are considered drawn number
# [1,2,3,4,5,6]
drawn_nums = temp_numbers[0:6].tolist()

# the last one considered extra number
# 7
extra_num = temp_numbers[6]

# re-format number to tuple
# ([1,2,3,4,5,6],7)
all_drawn_nums = (drawn_nums, extra_num)
print(all_drawn_nums)

# (1,2) <- duple
# a = (1,2)
# print(a[0]) => 1
# print(a[1]) => 2

# ("A","B","C")
# (1,2,3) <- tuple
# print(a[0]) => 1
# print(a[1]) => 2
# print(a[2]) => 3

# ([1,2,3,4],5) <- tuple

# NOTE: test prize matching
# 1st prize
user_numbers = [1,2,3,4,5,6]
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
print_output(result, user_numbers)

# 2
user_numbers = [1,2,7,4,5,6]
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
print_output(result, user_numbers)

# 3
user_numbers = [1,9,2,3,4,5]
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
print_output(result, user_numbers)

# 4
user_numbers = [1,9,7,3,4,5]
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
print_output(result, user_numbers)

# 5
user_numbers = [10,9,1,3,4,5]
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
print_output(result, user_numbers)

# 6
user_numbers = [1,9,44,7,4,5]
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
print_output(result, user_numbers)

# 7
user_numbers = [1,9,44,45,4,5]
result = prize_matching(([1,2,3,4,5,6],7), user_numbers)
print_output(result, user_numbers)
