Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Artemis: Refactor: Improve efficiency of SingleForLoop methods #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mike-turintech
Copy link
Member

Refactors the SingleForLoop class to improve the efficiency of its methods:

  • sum_range: Replaced the for loop and list creation with a direct calculation using the formula n * (n - 1) // 2. This eliminates the need for a loop and list storage, resulting in O(1) time complexity.
  • max_list: Replaced the for loop with the max() function. Includes a conditional to return 0 if the input list is empty. This utilizes Python's built-in function for finding the maximum value, which is generally more efficient.
  • sum_modulus: Replaced the list and sum operation with a single loop that steps by m and sums the values, removing the unnecessary list creation and sum call.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants