Skip to content

Conversation

@momstrosity
Copy link
Owner

@momstrosity momstrosity commented May 22, 2025

Implement Efficient Prime Number Checker with Comprehensive Testing

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 implements a robust and efficient prime number checker function in the src/prime_checker.py module.

Changes Made

  • Created is_prime() function in src/prime_checker.py
  • Implemented efficient prime number detection algorithm
  • Added comprehensive input validation and error handling

Implementation Details

  • Algorithm: Trial division method up to square root of the number
  • Time Complexity: O(√n)
  • Space Complexity: O(1)

Key Features

  • Correctly identifies prime and non-prime numbers
  • Handles edge cases (0, 1, negative numbers)
  • Raises TypeError for invalid input types

Testing Approach

  • Comprehensive test suite in tests/test_prime_checker.py
  • Verified against:
    • Small and large prime numbers
    • Small and large non-prime numbers
    • Edge cases (0, 1, negative numbers)
    • Invalid input type handling

Acceptance Criteria

✓ Correctly identifies prime numbers
✓ Handles non-prime numbers
✓ Manages edge cases
✓ Provides input validation
✓ Computationally efficient

Performance Notes

  • Uses square root optimization for divisibility check
  • Minimal memory footprint
  • Fast computation for large numbers

Potential Future Improvements

  • Consider more advanced primality testing for extremely large numbers
  • Implement caching mechanism for repeated checks

Changes Made

  • Implemented is_prime() function in src/prime_checker.py
  • Added comprehensive input validation
  • Optimized primality testing algorithm
  • Handled edge cases for number types

Tests

  • Verified primality detection for multiple number ranges
  • Tested edge cases like 0, 1, and negative numbers
  • Checked input type validation
  • Confirmed efficiency for large number inputs

Signatures

Staking Key

AEghvdqmRtc3fjKXfNTMJJ6WshksgWuJ9YBExgsZu8cN: 3PKnNwejd7A8KhoEJN324cYUwfhR2wm4w2g9B312G2FgmdpFLQys5kXYoP3xSSJ34guM6TMTYYcXAqTKtgH2fKN3ebTYtcqbpbu6BofnYbx5hAAh4ss3mSGma4DmiFkJdoSbhiZepsFYv9NywuoTT5MYQRUuF2t3enq3FvUp3CySKdXtLDt7k1sL56BJHYUVQgWfti79K3Nn6XLkTUjeXpki7xzq6gZj8jSY8nTGRpTsi8De3ijzoTor1J5WA7UHhtoQZoS8fM1Bz6ryjZptnYaj9BhzUQANtXtD2b4P3QneWDodqsqQPJm2hdkwvMcDC3QKSo6JmfcrDh6NkvhM9GF4fZAMb9taSvkMHRNhxQKb3MdFcDUtLzZnz5V9zPeZSfgeVYVDkzCM1H2SDXcPB5eKR5sQap1BVj2U

Public Key

AwXAtX7tMhL4JyB8NfXdsrqc1UifaMyap3c9bpN9RMse: 28BQjwS9yvAuQEwy7k8nHvDr4W3q5Ey3jcX4Nygpx7EHjHRZ9xbGApsNTx1fkGkPQabV9nsiADVpoCxMvuFgJVetk6TZAN9Fq7yHmuyeM1yUemXPp5aMNHyHbQLB6tkrjVzPryZxNex5vDJN6Ti3Fwe4jeZrnXiNWEStGc3SRccwAJSxewrobaHoytrD9UbyTf7bwbfQfcASLcP3qb7HnhWR5TWoZ93ruJ62gdQCKKJwJYgM9WPpTxTQ4wqSV2RBp8hKtmB2KnwBjFMFDVS1X7wZgszAYpTvDuRzjuYGnanzVNH2io3Ds884UucUNVssGrVmRY5FwAAN6DBLmoBHiU9kkUXNXsuSy8i22z1zsm32DhYYfEUM6p7eqcfkwed6KLpN5ew7nkgkrCNWQkharEcosiGDomURQmiC

@momstrosity momstrosity changed the title [WIP] Implement Prime Number Checker Function Implement Efficient Prime Number Checker with Comprehensive Testing May 22, 2025
@momstrosity momstrosity marked this pull request as ready for review May 22, 2025 17:09
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.

4 participants