Skip to content

Conversation

@labrocadabro
Copy link

Implement GCD Calculator Using Prime Factorization

Description

Task

Implement GCD Calculator Using Prime Factors

Acceptance Criteria

  • Use prime factorization function from previous todo
  • Calculate GCD using prime factors
  • Handle multiple input numbers
  • Optimize for efficiency

Summary of Work

Overview

This pull request implements a Greatest Common Divisor (GCD) calculator using prime factorization technique, leveraging the existing prime factorization functionality.

Changes Made

  • Created src/gcd_calculator.py with gcd_using_prime_factors() function
  • Implemented comprehensive GCD calculation using prime factors
  • Added extensive test cases in tests/test_gcd_calculator.py

Implementation Details

  • Uses prime_factorization() to break down numbers into their prime factors
  • Utilizes collections.Counter to efficiently count prime factor occurrences
  • Calculates GCD by finding the minimum count of common prime factors
  • Handles edge cases like:
    • Same number inputs
    • Coprime numbers
    • One number being a multiple of another
    • Invalid inputs (non-positive numbers)

Testing Approach

  • Implemented 5 test cases covering various scenarios:
    1. Basic GCD calculations
    2. GCD of same numbers
    3. GCD when one number is a multiple of another
    4. GCD of coprime numbers
    5. Error handling for invalid inputs

Acceptance Criteria

✅ Correctly calculates GCD using prime factorization
✅ Handles edge cases and error scenarios
✅ Well-documented and tested implementation
✅ Uses existing prime factorization functionality

Notes

  • Relies on src/prime_factorization.py for prime factor generation
  • Time complexity is O(sqrt(n)) due to prime factorization algorithm
  • Minimal additional dependencies required

Changes Made

  • Created src/gcd_calculator.py with gcd_using_prime_factors() implementation
  • Added comprehensive tests in tests/test_gcd_calculator.py
  • Used collections.Counter for efficient prime factor counting
  • Implemented robust error handling for invalid inputs

Tests

  • Verify basic GCD calculations
  • Test GCD with same number inputs
  • Check GCD when one number is multiple of another
  • Validate GCD of coprime numbers
  • Ensure proper error handling for invalid inputs

Signatures

Staking Key

7aAADu3aXXncSyvSVErKbQqGF3caWZkVz9MSLorvgv2f: 9M5j26NNS5nLa1CweXKYiDXUMpVwKUMy8Qved23PWikGxYYzitZcYSjkYDc1orxJFT633szyvD9trBYM3XSNmKrE7DLVfJ8c9U8QFhC5cCcg9LB5VZNAcHSR1izmBp5Go12BNQ4idVQBMoaRM8kc7oCM8MbyyuZShwnR3hajiUBskufgYZHZD1KU7yxHeTutM9xo6TKGSuyc8X8hrnbR7NVCnM6YkXpvRUqTkLJWFBb5bWRvUk1aX8GaBzgwKDkJQuoYn8UHocTBBge1pkbUHKUYNKExbNKVzJX7oaPd3QoMimVXDPuGXZ1pEHrNhfkz1wsDGtAyjjPrtsYUpNEtgsFQHTLLuRDCFVeF6p1sJ9WaughjYifGCKrsaEZJdvuRPVCZHnvHgZTLoJHjRdJz4Q1Yw5jJnZf4w2HZN

Public Key

2R7RRyEP2A4agg5rfY1HxPKhugqgDSnDmsbdZpkEcbeF: BHUVFvg4HJ1HH5btvJmNCpPvWjudZB3SH6BjUP2Nzbvt8BBidi7XKPzYMfxQAotxEHQtdFDaJt5kn1ChvgMjp9VTWuawfbdjq3L1hK3LhFh3ns6hafiHdA2fjTGg4UYiYPg9hY7T8ME8w5PF7VS6Z23HSjhn8y7MH3XNnLT3XBGvZiNa7v1wM6VzfSsUdSnc1n12i7tcqzE2bnnmQeBCZCekZJitktEkL2QFSciphRy7UcCzJ1ZpWN6aX9E3pRQ6T8ouAPpi8RE5LPbAfUZ97GyBZBauaKWenkHxWi6qytnxVSiX2AhR4hp4623vQ83eMTd9zqWNcH78oWu2eXzC6WPu3jHQ3ZgU2gAFZcnDsNa1s1u2TmZRHiePHJc194anqfQe7AVFV5XNAuXvNvSuuQ5viMv9APx1PLNBn

@laura-abro
Copy link
Owner

Number Theory Utility Functions

Description

Implementation of GCD calculator, Prime Checker, and Prime Factorization utility functions

Recommendation

APPROVE

Reasons:

  • All 16 tests passed successfully
  • Implementation follows good software engineering practices
  • Comprehensive error handling
  • Well-structured and modular code
  • Thorough test coverage for edge cases and error conditions

Unmet Requirements

All requirements met

Tests

Failed Tests

No failing tests

Missing Test Cases

No missing test cases identified

Action Items

  • Consider adding type hints to arguments in is_prime() function for better type checking
  • Optional: Add more comments explaining the prime factorization algorithm in the implementation

Signatures

Staking Key

5EmgCQSgPD79JWPQ6KMAV35kUNxasNQymeWuQXfJPmVk: bU5iqTZ6My6PfMWxY3Qp9CVe7UjDZdgnsZuYoyUB8PwxqJXs8QFmqoUEEFZJ1yeavvZbPwsafARwxcCqYDfrcQtr19xwrNvt13K3o2GsYjez9ib7FWvLHWnqhb6vpwvCjffgGMQUy9zLUtZcW711n3wUj7cA7jy4zWSrSHtzpnVHps6pBJwBC9HcCNddTbYEDpcj4yxiKHExekHvmtXivoWNc7MBY2xptC3ZoSCa9eD1RDQvFKHk84Y5m6VG4dejAfZhUWNPs9QqSVr

Public Key

8U4eXGpP28X2i8wDEDxwGUdSdPuz7xuMBvpFuVyPDNKz: 5xNHWXRi9hBeGwkxBiXsdSQsKKQybsYyfGuTrWw24F7pm8CQDp3V2TYiNG1HYdpnek8UVvgBCgaMTbCUGiE1fPeNFskpZHwnZbcJUYy7EZNSXyYFhArynawuHaR2ZLDHS8AsberFynPeN6DNJxtuDCqVS5tNdsQdABZE5XHYCNq4rhZKgmv9m7e66RfdACxzVrZnMt3pVuie5Z4oivS29s2sSYk9zkM2NfJyih4qJQ9JjAGw38SnuV3BJYayN3WUSvHzQ8X25aLHrX7a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants