diff --git a/collaboration/README.md b/collaboration/README.md index 8ef09088c..78b623ac6 100644 --- a/collaboration/README.md +++ b/collaboration/README.md @@ -2,8 +2,9 @@ --- -Our group is committed to fostering a collaborative environment that values trust, -open communication, mutual respect, and the celebration of diverse perspectives. +Our group is committed to fostering a collaborative environment that values +trust, open communication, mutual respect, and the celebration of diverse +perspectives. --- @@ -44,7 +45,8 @@ open communication, mutual respect, and the celebration of diverse perspectives. , and successes. - Show empathy and actively listen during discussions. - Celebrate both individual and team achievements. -- Address trust issues respectfully and take steps to rebuild confidence if broken. +- Address trust issues respectfully and take steps to rebuild confidence if + broken. --- @@ -53,7 +55,8 @@ open communication, mutual respect, and the celebration of diverse perspectives. - Ensure everyone has an opportunity to speak and contribute. - Avoid interrupting or dominating discussions. - Critique ideas, not people, and provide constructive feedback. -- Show appreciation for all contributions and avoid dismissing ideas prematurely. +- Show appreciation for all contributions and avoid dismissing ideas + prematurely. --- @@ -69,7 +72,8 @@ open communication, mutual respect, and the celebration of diverse perspectives. - Revisit group norms periodically (preferably, monthly) to adapt to new challenges or feedback. -- Allow flexibility for unforeseen circumstances but communicate changes promptly. +- Allow flexibility for unforeseen circumstances but communicate changes + promptly. --- @@ -90,4 +94,5 @@ open communication, mutual respect, and the celebration of diverse perspectives. --- -Let’s stay committed to these norms to ensure a productive and enjoyable collaboration. +Let’s stay committed to these norms to ensure a productive and enjoyable +collaboration. diff --git a/collaboration/learning_goals.md b/collaboration/learning_goals.md index 12d2e8e12..63de4f8d2 100644 --- a/collaboration/learning_goals.md +++ b/collaboration/learning_goals.md @@ -2,34 +2,44 @@ ## Collective -**1.Collaborative Coding**: Work together to develop efficient and innovative code -solutions to address real-world challenges. +**1. Collaborative Coding**: +Work together to develop efficient and innovative code solutions to address +real-world challenges. -**2.Code Review Skills**: Cultivate a constructive and effective peer-review process - to improve code quality and ensure best practices. +**2. Code Review Skills**: +Cultivate a constructive and effective peer-review process to improve code +quality and ensure best practices. -**3.Version Control Mastery**: Gain hands-on experience with Git and GitHub for -seamless collaboration, version control, and project management. +**3. Version Control Mastery**: +Gain hands-on experience with Git and GitHub for seamless collaboration, +version control, and project management. -**4.Team Communication**: Enhance teamwork and communication skills to ensure smooth - coordination and timely completion of tasks. +**4. Team Communication**: +Enhance teamwork and communication skills to ensure smooth coordination and +timely completion of tasks. -**5.Problem-Solving**: Address challenges creatively as a group by leveraging - diverse skills and perspectives. +**5. Problem-Solving**: +Address challenges creatively as a group by leveraging diverse skills and +perspectives. ## Individual -**1.Coding Proficiency**: Develop expertise in writing clean, efficient, and - functional code to contribute meaningfully to group projects. +**1. Coding Proficiency**: +Develop expertise in writing clean, efficient, and functional code to +contribute meaningfully to group projects. -**2.Feedback Skills**: Learn to provide and incorporate constructive feedback during - code reviews for continuous improvement. +**2. Feedback Skills**: +Learn to provide and incorporate constructive feedback during code reviews +for continuous improvement. -**3.Git and GitHub Skills**: Build individual proficiency in using Git commands and - GitHub workflows, including branching, merging, creating issues and resolving conflicts. +**3. Git and GitHub Skills**: +Build individual proficiency in using Git commands and GitHub workflows, +including branching, merging, creating issues, and resolving conflicts. -**4.Accountability**: Take responsibility for assigned tasks while meeting deadlines - and maintaining high-quality work. +**4. Accountability**: +Take responsibility for assigned tasks while meeting deadlines and +maintaining high-quality work. -**5.Adaptability**: Expand technical and collaborative skills by learning from peers -and adapting to project requirements. +**5. Adaptability**: +Expand technical and collaborative skills by learning from peers and +adapting to project requirements. diff --git a/solutions/5-calculate-the-factorial-of-a-number b/solutions/05_calculate_the_factorial_of_a_number.py similarity index 100% rename from solutions/5-calculate-the-factorial-of-a-number rename to solutions/05_calculate_the_factorial_of_a_number.py diff --git a/solutions/6-reverse-a-string.py b/solutions/06_reverse_a_string.py similarity index 100% rename from solutions/6-reverse-a-string.py rename to solutions/06_reverse_a_string.py diff --git a/solutions/find_partitions.py b/solutions/find_partitions.py index d2d86e5a0..932b61be0 100644 --- a/solutions/find_partitions.py +++ b/solutions/find_partitions.py @@ -1,3 +1,35 @@ +""" +Module: Partition Finder + +This module provides a function `find_partitions` that calculates all possible +partitions of a given number `n` using integers up to a specified maximum +value `max_num`. A partition of a number is a way of expressing it as a sum +of positive integers, regardless of order. + +Behavior: +- The function uses recursion to explore all valid partitions of `n`. +- It ensures the partitions are unique and sorted. +- The implementation handles base cases for invalid inputs and recursively + builds partitions by including and excluding the current `max_num`. + +Implementation: +1. Base cases: + - If `n` is negative or `max_num` is 0, return an empty list (no partitions). + - If `n` equals `max_num`, include the partition `[max_num]`. +2. Recursive calls: + - Find partitions including `max_num` by subtracting it from `n`. + - Find partitions excluding `max_num` by reducing `max_num`. +3. Combine results: + - Return all valid partitions by concatenating and sorting the partitions + from the above steps. + +Example: + Input: n = 6, max_num = 4 + Output: [[4, 2], [4, 1, 1], [3, 3], [3, 2, 1], [3, 1, 1, 1], [2, 2, 2], + [2, 2, 1, 1], [2, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]] +""" + + def find_partitions(n, max_num): """ Find all possible partitions of a number `n` using integers from 1 to `max_num`. @@ -14,28 +46,52 @@ def find_partitions(n, max_num): - list of lists: A list containing all partitions, where each partition is a list of integers that sum to `n`. All numbers used are <= `max_num`. """ - # Base case: If n is negative or max_num is 0, return an empty list if n < 0 or max_num == 0: return [] - # Initialize a list for partitions that exactly match n exact_match = [] - - # If n equals max_num, include the partition [max_num] if n == max_num: exact_match = [[max_num]] - # Find partitions that include max_num by subtracting it from n with_max_num = [ partition + [max_num] for partition in find_partitions(n - max_num, max_num) ] - - # Find partitions that exclude max_num by reducing max_num without_max_num = find_partitions(n, max_num - 1) - # Return combined partitions: exact matches, with max_num, and without max_num return sorted(exact_match) + sorted(with_max_num) + sorted(without_max_num) -# Example usage: Find partitions of 6 using numbers from 1 to 4 -print(find_partitions(6, 4)) +# Add test cases for the function +if __name__ == "__main__": + expected_result_case_1 = [ + [1, 1, 4], + [2, 4], + [1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 2], + [1, 1, 1, 3], + [1, 1, 2, 2], + [1, 2, 3], + [2, 2, 2], + [3, 3], + ] + expected_result_case_2 = [ + [1, 1, 3], + [2, 3], + [1, 1, 1, 1, 1], + [1, 1, 1, 2], + [1, 2, 2], + ] + expected_result_case_3 = [[1, 1, 2], [2, 2], [1, 1, 1, 1]] + expected_result_case_4 = [[1, 1, 1]] + expected_result_case_5 = [] + expected_result_case_6 = [] + + # Test cases for correctness + assert find_partitions(6, 4) == expected_result_case_1, "Test case 1 failed" + assert find_partitions(5, 3) == expected_result_case_2, "Test case 2 failed" + assert find_partitions(4, 2) == expected_result_case_3, "Test case 3 failed" + assert find_partitions(3, 1) == expected_result_case_4, "Test case 4 failed" + assert find_partitions(0, 5) == expected_result_case_5, "Test case 5 failed" + assert find_partitions(-1, 3) == expected_result_case_6, "Test case 6 failed" + + print("All test cases passed!") diff --git a/solutions/tests/test 5-calculate-the-factorial-of-a-number b/solutions/tests/test_05_calculate_the_factorial_of_a_number.py similarity index 100% rename from solutions/tests/test 5-calculate-the-factorial-of-a-number rename to solutions/tests/test_05_calculate_the_factorial_of_a_number.py diff --git a/solutions/tests/test 6-reverse-a-string.py b/solutions/tests/test_06_reverse_a_string.py similarity index 100% rename from solutions/tests/test 6-reverse-a-string.py rename to solutions/tests/test_06_reverse_a_string.py diff --git a/solutions/tests/test_find_partitons.py b/solutions/tests/test_find_partitons.py deleted file mode 100644 index bc42b43bf..000000000 --- a/solutions/tests/test_find_partitons.py +++ /dev/null @@ -1,105 +0,0 @@ -""" -Tests for the find_partitions function from the find_partitions.py module -Run with `python3 -m unittest test_find_partition.py` -""" - -import unittest - - -def find_partitions(n, max_num): - """ - Find all possible partitions of a number `n` using integers from 1 to `max_num`. - - A partition of `n` is a way of writing it as a sum of positive integers, where - the order of terms doesn't matter. This function returns all unique partitions - of `n` using numbers from 1 to `max_num`. - - Parameters: - - n (int): The number to be partitioned. - - max_num (int): The largest integer that can be used in the partition. - - Returns: - - list of lists: A list containing all partitions, where each partition is a - list of integers that sum to `n`. All numbers used are <= `max_num`. - """ - # Base case: If n is negative or max_num is 0, return an empty list - if n < 0 or max_num == 0: - return [] - - # Initialize a list for partitions that exactly match n - exact_match = [] - - # If n equals max_num, include the partition [max_num] - if n == max_num: - exact_match = [[max_num]] - - # Find partitions that include max_num by subtracting it from n - with_max_num = [ - partition + [max_num] for partition in find_partitions(n - max_num, max_num) - ] - - # Find partitions that exclude max_num by reducing max_num - without_max_num = find_partitions(n, max_num - 1) - - # Return combined partitions: exact matches, with max_num, and without max_num - return sorted(exact_match) + sorted(with_max_num) + sorted(without_max_num) - - -# Example usage: Find partitions of 6 using numbers from 1 to 4 -print(find_partitions(6, 4)) - - -class TestFindPartitions(unittest.TestCase): - def compare_unordered_lists(self, list1, list2): - """ - Compare two lists of lists in an unordered fashion. - Sort each sublist before comparing the lists themselves. - """ - # Sort the sublists within both lists - list1_sorted = [sorted(sublist) for sublist in list1] - list2_sorted = [sorted(sublist) for sublist in list2] - - # Sort the entire lists to compare unordered contents - return sorted(list1_sorted) == sorted(list2_sorted) - - def test_partition_basic(self): - # Test for small basic cases - result = find_partitions(6, 4) - expected = [ - [2, 4], - [1, 1, 4], - [3, 3], - [1, 2, 3], - [1, 1, 1, 3], - [2, 2, 2], - [1, 1, 2, 2], - [1, 1, 1, 1, 2], - [1, 1, 1, 1, 1, 1], - ] - self.assertTrue(self.compare_unordered_lists(result, expected)) - - def test_partition_zero(self): - # Test for partitioning 0 (should return an empty partition) - self.assertEqual(find_partitions(0, 5), []) - - def test_partition_one(self): - # Test for partitioning 1 (should return [[1]]) - self.assertEqual(find_partitions(1, 1), [[1]]) - - def test_partition_empty_case(self): - # Test with n = 5 but max_num = 0 (should return an empty list) - self.assertEqual(find_partitions(5, 0), []) - - def test_partition_negative(self): - # Test for partitioning a negative number (should return an empty list) - self.assertEqual(find_partitions(-1, 5), []) - - def test_partition_no_valid_parts(self): - # Test where n = 3 and max_num = 2 (only partitions using 1 and 2) - result = find_partitions(3, 2) - expected = [[2, 1], [1, 1, 1]] - self.assertTrue(self.compare_unordered_lists(result, expected)) - - -if __name__ == "__main__": - unittest.main()