Skip to content

Conversation

@momstrosity
Copy link
Owner

@momstrosity momstrosity commented May 22, 2025

Implement Efficient Prime Number Checker 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

Prime Number Checker Implementation

Changes Made

  • Implemented is_prime() function in src/prime_checker.py
  • Created a robust and efficient algorithm for primality testing
  • Added comprehensive error handling and input validation

Implementation Details

  • The is_prime() function provides an efficient primality check with O(√n) time complexity
  • Handles various edge cases including:
    • Negative numbers
    • Zero and one
    • Large prime and non-prime numbers
  • Strict type checking to prevent invalid input
  • Algorithm optimizations:
    • Early return for numbers ≤ 1
    • Special handling for 2 (smallest prime)
    • Skipping even numbers after 2
    • Checking divisibility only up to square root

Testing Approach

  • Comprehensive test suite covering:
    • Known prime numbers
    • Known non-prime numbers
    • Large prime and non-prime numbers
    • Negative numbers
    • Invalid input types
  • All 6 test cases in test_prime_checker.py passed successfully

Acceptance Criteria

  • ✅ Correctly identifies prime numbers
  • ✅ Handles edge cases (0, 1, negative numbers)
  • ✅ Provides type checking and error handling
  • ✅ Efficient implementation with optimal time complexity

Additional Notes

  • Tested with numbers up to 104,729
  • Provides clear, readable, and well-documented implementation
  • Future improvements could include more advanced primality testing for extremely large numbers

Changes Made

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

Tests

  • Verified primality of small prime numbers
  • Checked handling of non-prime numbers
  • Tested large prime and non-prime numbers
  • Validated error handling for invalid inputs
  • Ensured correct behavior for edge cases

Signatures

Staking Key

AEghvdqmRtc3fjKXfNTMJJ6WshksgWuJ9YBExgsZu8cN: 2cnxFV6fviaAR5sBYMdKT6QSYeuL4oGst3UURtWFfRiNtTvpztKaxLTC381DKQaeWg7HxKsGypVKNxh29xC441xRuy7NWQiWiTW5ttr64KpqTBMtjcGzV2f2x31GPM2oShwsQyGYevD1ZtsuhPqrKdws2UqqTDhaDXcakGcs5Ti3v76bpkYgvFqomHSPzoRdzcJyFFidpCzSjtn1q3KtnMTYuBQZ62wQQcFXEkDAKr8Z1simkh2S1yR53w2RHogEfGd4PzgGxdg6drzpAfHwTjBge3KvCrGZRXgnsvFLXzXaLeMi7vf12vnnXYgMYYSTpHVv95Byqvsd6WpwYKT8SYU9fUrbKymJY15QLpMRiUoQ27X19k8GQaTfuC4ti1YMJ4veytBrHhaxvUBSYwmJZmeGhCsV1AApmnZz

Public Key

AwXAtX7tMhL4JyB8NfXdsrqc1UifaMyap3c9bpN9RMse: 2qqEkYuiKs5gRqFKVh1QMGrYjEjCpvGAmuHYnD6bY4Bi3mYTvrAVXUjDnup5CFKghFRoSywd7WDnB2YNVnqVKP8GiKM33d3XSWsskEq23ShT4GTQgWPnumXuSU8fpnXMtPH1qzckAhJYsdHb3wBSKSEgz2ewpppn7JNawzXqwu5ihUVX7EmDRLC3XrYj4FACZKijAH6ijhpZE2VXPAWUvnMo24XhpXcRbQ4UxrcetFKjZnSfmxZ8suSwz6TFZgpzTFZKzZr7PFefY9ZPHcMqb9WG8n88LRE7YoP6uuLpogi1kMzZTTisimtuxBjBFjmPfa2LDJy5wiSfVPodgkVoVgsReDXiNB7fKD3vT65CJmcsxGy5ZfneUbz1fWbBiTPtKGbrb7YR55qpzoTGfRetitsAcdesG1njxyfi

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