Generation

generate functionThu, 06 Apr 2023

Q,W,E,R,T,Y,U,I,O,P,A,S,D,F are 14 members belongs to G1,G2 and G3 following G1(Q,W,E,R,T) G2(Y,U,I,O,P,A) and G3(S,D,F) are 3 groups with 14 members in total and get 7 members out of each groups without repeating and where you can select only ( max 3 or 1 member from G1),(max 4 and min 2 from G2) and ( max 2 and min 1 from G3)

def get_member(nums, max_num, min_num=1): if nums < max_num: return [nums] if nums == max_num: return [nums] if nums > max_num: if nums - max_num < min_num: return [nums - max_num, max_num] else: return [min_num, nums - min_num] def get_groups(nums): m1 = get_member(nums[0], 3, 1) m2 = get_member(nums[1], 4, 2) m3 = get_member(nums[2], 2, 1) return [m1, m2, m3] get_groups([4, 4, 2])

Questions about programming?Chat with your personal AI assistant