<commit_before>names_master = ["<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","FJ","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","JillianC","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","wolv","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>"]

## PSEUDOCODE
# Create results array, which will be an array of group arrays
# Iterate through names master list array with indexes
# Push each name into array to hold the small group
# If the index+1 is divisible by 4
# 	The array is finished
#   Push the array into the results array
# If the final group array has fewer than 3 people
#  	Put the first person into the second-to-last group
#  	Put the second person (if there is one) into the third-to-last group
# Return the results array 
# Perhaps make a results hash that has "Group 1" as the key, and the group array as the value


def make_groups(name_master_list, group_size, min_group_size)
	groups = {}
	group_num = 1
	name_master_list.each_with_index do |name, index|
		groups["Group #{group_num}"] ||= []
		groups["Group #{group_num}"] << name
		if (index + 1) % group_size == 0 || name_master_list[index + 1] == nil
			group_num += 1
		end
	end
	groups
end

p make_groups(names_master, 4, 3)<commit_msg>Add print functionality<commit_after>names_master = ["<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","FJ","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","JillianC","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","wolv","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>","<NAME>"]

## PSEUDOCODE
# Create results array, which will be an array of group arrays
# Iterate through names master list array with indexes
# Push each name into array to hold the small group
# If the index+1 is divisible by 4
# 	The array is finished
#   Push the array into the results array
# If the final group array has fewer than 3 people
#  	Put the first person into the second-to-last group
#  	Put the second person (if there is one) into the third-to-last group
# Return the results array 
# Perhaps make a results hash that has "Group 1" as the key, and the group array as the value


def make_groups(name_master_list, group_size, min_group_size, shuffle_first = false)
	groups = {}
	# Set initial group number
	group_num = 1
	name_master_list.shuffle! if shuffle_first
	
	name_master_list.each_with_index do |name, index|
		# Set the value as an empty array if it doesn't already exist
		groups["Group #{group_num}"] ||= [] 
		groups["Group #{group_num}"] << name
		# Test whether we have either reached the group size already
		# Or if we have reached the final name (The item at the next index is nil)
		if (index + 1) % group_size == 0 && name_master_list[index + 1] != nil
			# Time to make a new group with a new group number
			group_num += 1
		end
	end

	# The last group will be the one with the current group_num value
	last_group = groups["Group #{group_num}"]
	# Test if the last group is too small; if so, add its members to the other groups
	if last_group.length < min_group_size
		# Make the second-to-last group the new group for the first member
		new_group_num = group_num - 1
		last_group.each do |name|
			# Put the member into its new group
			groups["Group #{new_group_num}"] << name
			# Set a different new group for the next member
			new_group_num -= 1
		end
		# Get rid of the group that was too small, now that its members have new groups
		groups.delete("Group #{group_num}")
	end

	return groups
end


def make_and_print_groups(name_master_list, group_size, min_group_size, shuffle_first = false)
	make_groups(name_master_list, group_size, min_group_size, shuffle_first).each do |k, v|
		puts "#{k}: #{v.join(', ')} \n\n"
	end
end

make_and_print_groups(names_master, 4, 3, true)
{'fraction_non_alphanumeric': 0.21869639794168097, 'fraction_numerical': 0.005145797598627788, 'mean_word_length': 6.210200927357032, 'pattern_counts': {'":': 0, '<': 160, '<?xml version=': 0, '>': 153, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1033854', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1630, 'n_words': 446}