Skip to content

Conversation

@momstrosity
Copy link
Owner

@momstrosity momstrosity commented May 8, 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

Overview

This pull request implements a robust and efficient prime number checker function that determines whether a given integer is prime.

Changes Made

  • Created src/prime_checker.py with an optimized prime number checking algorithm
  • Implemented comprehensive test suite in tests/test_prime_checker.py

Implementation Details

Prime Number Checker Function (is_prime)

  • Handles integer input validation
  • Efficiently checks primality using optimized algorithm
  • Time complexity: O(√n)
  • Handles edge cases:
    • Numbers less than 2 (not prime)
    • Special cases for 2 (prime)
    • Even numbers greater than 2 (not prime)
    • Checks only odd divisors up to square root

Testing Approach

  • Comprehensive test coverage including:
    • Positive prime numbers
    • Negative numbers
    • Edge cases (0, 1, 2)
    • Large prime and non-prime numbers
    • Type error handling
  • 6 distinct test cases covering various scenarios
  • All tests passing successfully

Acceptance Criteria

✓ Correctly identifies prime numbers
✓ Handles various input types and edge cases
✓ Efficient algorithmic implementation
✓ Comprehensive error handling
✓ Full test coverage

Performance Considerations

  • Optimized primality check
  • Early return for known non-prime scenarios
  • Minimal computational overhead

Notes

  • Requires Python 3.6+
  • Uses type hinting for improved readability
  • Raises TypeError for non-integer inputs

Changes Made

  • Created src/prime_checker.py with prime number checking function
  • Implemented efficient primality checking algorithm
  • Added comprehensive error handling
  • Created tests/test_prime_checker.py with multiple test scenarios
  • Verified type checking and input validation

Tests

  • Verified identification of prime numbers
  • Tested handling of edge cases (0, 1, 2)
  • Checked large prime and non-prime number detection
  • Validated error handling for invalid input types
  • Ensured computational efficiency

Signatures

Staking Key

AEghvdqmRtc3fjKXfNTMJJ6WshksgWuJ9YBExgsZu8cN: 3N85G7USe9SFfZL4G7WbG4YUPm3QjuJbrcC8aNCUi6hwdHgyFVYp7YydxFQh1yBotZ2Zf3UyCB3kbh7wHMHKStCqyytAx1xJeKR11Y1G2MNr1wKeLAXcadj2EWpxsozgrn9p8FFTGmm4CiCi1VQvJxJgSQQZgs5Kf8Hv28iZjDKxQtSrPoT8Nfy63QGcULi3pjdYLi4Lbb65ZGCpqbjhaA2Dz4Ta6oEkVxYhKNL9vzKP9Kn9LZX3W54wxh8b4sbkRzRhzNR1aRvJ5BwQW5ho6UEHXucqCFBfnMEmgQi2Vq3itwcBLNK3A629oz14QBLLmjThdkQRWyBGRdxkktKo96CDYUsik3a82EyzjJo1mit6PdMs41EptVf7ZcCbp5GP8ry7eUiDZGXs8ERj4H43eTNu6VC6RbH9kGp4

Public Key

AwXAtX7tMhL4JyB8NfXdsrqc1UifaMyap3c9bpN9RMse: 31J8Nk9JjsjN6sMLtMJo8Edjydemuv9AYJsdaxtWiYUGH61HAbYcpMti7Rwy3a5MCQmUzyYAYZAHwtMbAexqzENuDwGYs47pybAgvbUtHzpi7BWUZnLAceqpEXyFRYX24mG25HqcS3QuZMJA6AckjFhDzkzWj5Uez8AFJe9j7GG9FtxjAckkLV5yX2VwxtfD511nt7Sp5RQW7bhvgi54NDaeuo2M1yDuD45CWNeYi9EEx5hfytntT6hxjkobv4rS8BVVrcBDJ1VzowDW2iPwiVssMweJHFxgurijoFUHgLtnQUoeFEsdhHBmjgcDFdvFCQcdxTAcbERhmzbaF9LYNcw4CBBCuPucd5ATr93QwF9tGo71gD7nJXhgbAMe5LoDwzE9jLjPZmBoUXxZjT6zrrnxYDBt9Hx2wpg

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