Skip to content

Instantly share code, notes, and snippets.

@DickyT
Created November 27, 2015 00:34
Show Gist options
  • Save DickyT/5a8d665d14804ce5fa04 to your computer and use it in GitHub Desktop.
Save DickyT/5a8d665d14804ce5fa04 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import random
def generate_draw(n):
result_array = []
for i in range(n):
current_rand = None
check_passed = True
while current_rand is None or check_passed is False:
current_rand = random.randint(1, 49)
for each_int in result_array:
if each_int is current_rand:
check_passed = False
break
else:
check_passed = True
result_array.append(current_rand)
return result_array
def count_matches(test_arr, ref_arr):
match_arr = []
for each_test in test_arr:
for each_ref in ref_arr:
if each_test is each_ref:
match_arr.append(each_test)
return len(match_arr)
def compute_profit(customer_arr, ref_arr):
earn_count = len(customer_arr) * 2
give_out_count = 0
for each_lott_arr in customer_arr:
match_count = count_matches(each_lott_arr, ref_arr)
if match_count is 3:
give_out_count += 4
elif match_count is 4:
give_out_count += 10
elif match_count is 5:
give_out_count += 500
elif match_count is 6:
give_out_count += 100000
print 'Lottery profit $%s, give out $%s' % (earn_count, give_out_count)
sales_db = [generate_draw(6), generate_draw(6)]
reference_arr = generate_draw(6)
compute_profit(sales_db, reference_arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment