Skip to content

Instantly share code, notes, and snippets.

@warpgate3
Last active November 7, 2019 07:13
Show Gist options
  • Save warpgate3/c6e8e2d578e6a94c7abefe18329f4d31 to your computer and use it in GitHub Desktop.
Save warpgate3/c6e8e2d578e6a94c7abefe18329f4d31 to your computer and use it in GitHub Desktop.
rate rowbdugi
import random
from collections import Counter
def chk_made(target):
t = []
n = []
for c in target:
t.append(c[0])
n.append(c[1:])
s1 = set(t)
s2 = set(n)
if len(s1) != 4:
return False
else:
if len(s2) != 4:
return False
return True
def c_sort(c):
return sorted(c, key=lambda x: int(x[1:]))
def get_count_match_shape(u):
t = []
for c in u:
t.append(c[0])
s1 = set(t)
return len(s1)
def get_match_index_shape(u):
match_idx = []
for idx, val in enumerate(u):
for i in range(idx + 1, len(u)):
if get_only_shape(u[i]) == get_only_shape(val):
match_idx.append(i)
return match_idx
def get_match_index_number(u):
match_idx = []
for idx, val in enumerate(u):
for i in range(idx + 1, len(u)):
if get_only_number(u[i]) == get_only_number(val):
match_idx.append(i)
return match_idx
def get_mini_number(u):
return c_sort(u)[3]
def get_only_number(in_val):
return int(in_val[1:])
def get_only_shape(in_val):
return in_val[0]
def exchange_c(all_users, dk):
result = []
for idx, u in enumerate(all_users):
u = c_sort(u)
if chk_made(u):
number = get_mini_number(u)
print('user:', idx, 'made:', number)
if get_only_number(number) <= 7:
get_only_number(number)
else:
shape1 = get_match_index_shape(u)
shape2 = get_match_index_number(u)
shape3 = shape1 + shape2
s = set(shape3)
# print(u, s)
for val in s:
u[val] = dk.pop(0)
# print(u)
u = c_sort(u)
result.append(u)
return result
def build_up(n):
global sad
print('\n' * 2)
box1 = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8', 'H9', 'H10', 'H11', 'H12', 'H13']
box2 = ['C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'C11', 'C12', 'C13']
box3 = ['D1', 'D2', 'D3', 'D4', 'D5', 'D6', 'D7', 'D8', 'D9', 'D10', 'D11', 'D12', 'D13']
box4 = ['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'S11', 'S12', 'S13']
dk = box1 + box2 + box3 + box4
u1 = []
u2 = []
u3 = []
u4 = []
u5 = []
all_u = [u1, u2, u3, u4, u5]
# all_u = [u1, u2, u3, u4]
random.shuffle(dk)
# init
for i in range(0, 4):
for u in all_u:
u.append(dk.pop(0))
# stage 1
c1 = exchange_c(all_u, dk)
for idx, user in enumerate(c1):
if chk_made(user):
# print(idx, user, get_only_number(get_mini_number(user)))
result_make.append(get_only_number(get_mini_number(user)))
print('morning','-' * 100)
# print('stage1', c1)
# stage 2
print('noon','-' * 100)
# print('stage1', c1)
c2 = exchange_c(c1, dk)
# print('stage2', c2)
# stage 3
print('evening','-' * 100)
# print('stage1', c1)
c3 = exchange_c(c2, dk)
# print('stage3', c3)
# print(all_u)
fine = []
for idx, user in enumerate(c3):
if chk_made(user):
fine.append(get_only_number(get_mini_number(user)))
print(idx, user, get_only_number(get_mini_number(user)))
l = sorted(fine)
if len(l) > 1:
if l[1] - l[0] < 2:
if l[1] < 8:
sad = sad + 1
print('^^', l)
print(n, '=' * 100)
print(' ' * 100)
result_make = []
sad = 0
for n in range(0, 100):
build_up(n)
# print(sorted(result_make))
print(Counter(sorted(result_make)))
print('TT', sad)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment