<commit_before>#Pseudocode
#Input: Array of cohort names (first and last name is one element) and number of groups(maybe)
#Steps:
  #Create a container that can store a student name and their assigned accountability group
  #Go through every item in the list of names and add as a key to the container
  #Assign an accountability group 1 - 14 for each person as their associated value
  #Return the container
#Output: Hash consisting of student name and their assigned accountability group



names = ["<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>", "<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>"]

#Initial Solution
# def acct_groups(students)
#   cohort = {}
#   n = 1
#   students.each do |name|
#     cohort[name] = "Acct Group #{n}"
#     n < 14 ? n += 1 : n = 1
#   end

#   return cohort.sort_by { |k,v| v }.to_h
# end

# puts acct_groups(names)



#Add Complexity

# def acct_groups(students)
#   cohort = {}
#   n = 1
#   students.each do |name|
#     cohort[name] = "Acct Group #{n}"
#     n < 14 ? n += 1 : n = 1
#   end

#   n = 1
#   until n == 15
#     puts cohort.select {|key, value| value == "Acct Group #{n}"}
#     n += 1
#   end

# end

# puts acct_groups(names) #Output will print grouped by accountability group for better readability



#Refactored Solution

def acct_groups(students, groups=14)
  cohort = {}
  n = 1
  students.each do |name|
    cohort[name] = "Acct Group #{n}"
    n < groups ? n += 1 : n = 1
  end

  n = 1
  until n > groups
    puts cohort.select {|key, value| value == "Acct Group #{n}"}
    n += 1
  end

end

puts acct_groups(names, 15)
<commit_msg>Add solution file for challenge 5.6<commit_after>#Pseudocode
#Input: Array of cohort names (first and last name is one element) and number of groups(maybe)
#Steps:
  #Create a container that can store a student name and their assigned accountability group
  #Go through every name in the list and add as a key to the container
  #Assign an accountability group 1 - 14 for each person as their associated value
  #Return the container
#Output: Hash consisting of student name and their assigned accountability group

names = ["<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>", "<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>"]

#Initial Solution
def acct_groups(students)
  cohort = {}
  n = 1
  students.each do |name|
    cohort[name] = "Acct Group #{n}"
    n < 14 ? n += 1 : n = 1
  end

  return cohort.sort_by { |k,v| v }.to_h
end

puts acct_groups(names)



#Add Complexity

def acct_groups(students)
  cohort = {}
  n = 1
  students.each do |name|
    cohort[name] = "Acct Group #{n}"
    n < 14 ? n += 1 : n = 1
  end

  n = 1
  until n == 15
    puts cohort.select {|key, value| value == "Acct Group #{n}"}
    n += 1
  end
end

acct_groups(names) #Output will print grouped by accountability group for better readability



#Refactored Solution

def acct_groups(students, groups=14)
  cohort = {}
  n = 1
  students.each do |name|
    cohort[name] = "Acct Group #{n}"
    n < groups ? n += 1 : n = 1
  end

  n = 1
  until n > groups
    puts "Accountability Group #{n}: "
    puts cohort.select {|key, value| value == "Acct Group #{n}"}.keys
    puts
    n += 1
  end
end

acct_groups(names, 15) #Output will be formatted in a more readabe way

# What was the most interesting and most difficult part of this challenge?
  #The most insteresting part was playing with different methods to see the different ways I could output the data. The most difficult part was deciding if I wanted to use an array or a hash. I started second guessing myself when I was writing the initial solution but I continued on and I like the way my program executes now.

# Do you feel you are improving in your ability to write pseudocode and break the problem down?
  #Yes - it was hard for me at first but the more I do it the better I get. This was the easiest time I've had so far writing the pseudocode.

# Was your approach for automating this task a good solution? What could have made it even better?
  #I think it was a good approach because it's not too lengthy and it did a good job of outputting the same groups every time I ran the program. If I removed a few people the groups were still well balanced. To make this better I think it would make sense to create a seperate method for the printing of the list.

# What data structure did you decide to store the accountability groups in and why?
  #I ended up using a hash because I didn't want each accountability group to be completely seperate. I wanted every student to be part of one object (the cohort hash), and then assign each student a group from there.

# What did you learn in the process of refactoring your initial solution? Did you learn any new Ruby methods?
  #I played around with the .sort_by and .select methods for outputting the data. I ended up using the .select method when I refactored my solution because it allowed me to present data that was more readable when printed to the console.

{'fraction_non_alphanumeric': 0.16795398520953164, 'fraction_numerical': 0.008874281018898932, 'mean_word_length': 3.9600651996740015, 'pattern_counts': {'":': 0, '<': 141, '<?xml version=': 0, '>': 137, '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': '1641835', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1816, 'n_words': 854}