Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Goldbach's conjecture Algorithm #908

Open
lemorage opened this issue Nov 24, 2023 · 4 comments
Open

Add Goldbach's conjecture Algorithm #908

lemorage opened this issue Nov 24, 2023 · 4 comments

Comments

@lemorage
Copy link

Goldbach's conjecture states that every even natural number greater than 2 is the sum of two prime numbers.

@jaki729
Copy link

jaki729 commented Nov 26, 2023

def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def goldbach_conjecture(even_number):
    if even_number <= 2 or even_number % 2 != 0:
        print("Please provide an even number greater than 2.")
        return

    for i in range(2, even_number // 2 + 1):
        if is_prime(i) and is_prime(even_number - i):
            print(f"{even_number} = {i} + {even_number - i}")
            return

    print("Goldbach's conjecture is not applicable for this even number.")

# Example usage
even_number_to_check = 28  # Replace this with any even number greater than 2
goldbach_conjecture(even_number_to_check)

@lemorage
Copy link
Author

There is already a prime_check function out of there, maybe using this would be better?

@jaki729
Copy link

jaki729 commented Nov 27, 2023

Yes, thats correct but using square root method used for the calculations of prime numbers is the effecient and loogical way for doing it as it is also good for large numbers or big integer values. And Goldbach's conjecture algorithm is the unsolved art of mathematics.

@lemorage
Copy link
Author

Ya, quite reasonable, I agree.

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

No branches or pull requests

2 participants