Skip to content

Conversation

@momstrosity
Copy link
Owner

@momstrosity momstrosity commented May 20, 2025

Implement Efficient Prime Number Checking Function

Description

Task

Implement Prime Number Checker

Acceptance Criteria

  • Function should return boolean indicating if number is prime
  • Implement efficient primality test
  • Handle edge cases (negative numbers, 0, 1)
  • Include unit tests for various cases

Summary of Work

Overview

This pull request adds a robust and efficient prime number checking function to the project, providing a reliable way to determine whether a given integer is prime.

Changes Made

  • Created src/prime_checker.py with a comprehensive is_prime() function
  • Implemented an efficient primality checking algorithm
  • Added comprehensive test suite in tests/test_prime_checker.py

Implementation Details

Prime Number Checker Function

  • Algorithm uses optimized primality checking:
    • Handles edge cases (0, 1, negative numbers)
    • Checks only odd divisors up to square root of the number
    • Performs early returns for even numbers and known non-primes
  • Includes type checking and input validation
  • Raises ValueError for invalid input types

Testing Approach

  • Implemented 5 distinct test cases covering:
    1. Small prime numbers
    2. Small composite numbers
    3. Larger prime and composite numbers
    4. Edge cases (0, 1, negative numbers)
    5. Invalid input type handling

Test Results

  • All 5 test cases passed successfully
  • 100% coverage of critical input scenarios
  • Verified function correctness and robustness

Acceptance Criteria

  • ✅ Correctly identifies prime numbers
  • ✅ Handles edge cases and invalid inputs
  • ✅ Provides clear and efficient implementation
  • ✅ Includes comprehensive test coverage

Notes

  • Time complexity: O(√n)
  • Space complexity: O(1)
  • Suitable for checking primality of moderate-sized integers

Changes Made

  • Created src/prime_checker.py with is_prime() function
  • Implemented efficient primality checking algorithm
  • Added comprehensive error handling
  • Created tests/test_prime_checker.py with multiple test scenarios

Tests

  • Verify identification of small prime numbers
  • Verify identification of small composite numbers
  • Test edge cases (0, 1, negative numbers)
  • Validate handling of invalid input types
  • Check performance with larger numbers

Signatures

Staking Key

AEghvdqmRtc3fjKXfNTMJJ6WshksgWuJ9YBExgsZu8cN: 2CBqNbPr3BeS9EbjPJd1JHYT8LxzmXHCgmBU2ThyAXerHz5z1x69jvjdmkPo7vwfNc1jw885DWHg4Uu1dkkDTcXaPgsJyxfvJNrmTDVPQe19oC7JsoG7Zvonk25T976QcQZT2skfCDBMNCMmZcEbcmBoW2jTWnvrvmZ1U2qGeBDSjUkCtC4z1yGkpp1x2TeAGUdnUvPD4bpmn983N7kAJwDuuETyiGjUNjVLagisi4osDH2CJhbjt483whhreCYfJ6rJziup51ytEUNXHN3xH4qdUvTyPz7TpLpYKNsNxNCLgqCD1tTxgfAip4m57jm2MLhJCGQVrKUjUM69n36dxM7zKEE7DmAcaKNboG4TtTJDPYmFSmPseauBgK1XQgTgRtwNvWJyrMkVbx1iMnroydbrwVFpeS8knnQU

Public Key

AwXAtX7tMhL4JyB8NfXdsrqc1UifaMyap3c9bpN9RMse: 31etN4he46PxHcqR4N2v8Y9FcXpMuR29XXgFqyNoyrkiC33E5h5At5ZKCJLw12WuM8Ejia3uWHxuX88U46awHpZYfFMY98W9A5YUeqZKLzFe5vH8mBLXjswWVpWnBbXHJtBjyzJrf62iy7daa8ynGMgtCkjoQ5fMPG1FWVNxhu4veCnTYvP26SYiq75YZkYSwFiDuEM9uEDvfRcPDVqx4t4VV9usmTERJsQh5crLKDJBiYhwQgDiPi4D6TTFRz94gP3cMNMD2oMKET9Mn6xmb7UyLyNnXj7NQiFg7AaZscvy9KDDPNYxC7xf2MkZDMPdKQaU9AgVoHvRaBrtpZXJrFDLfJYxRCEBu8U3pnEKSFYbFZ7zb3mmH5DNB8Uec93A5sKH5YgKQ4ojMCBQHB7XMpXazc5WCEAmegqz

@momstrosity momstrosity changed the title [WIP] Implement Prime Number Checking Function Implement Efficient Prime Number Checking Function May 20, 2025
@momstrosity momstrosity marked this pull request as ready for review May 20, 2025 21:18
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.

2 participants