What programming language you start with really all depends on where you want to go with programming/coding. The great thing about this field is that there are an absolute abundance of smaller fields that you can go into, all using programming in their own unique ways. For web applications, a good start would be with HTML and later moving your way through CSS, JavaScript, JQuery, PHP, SQL, and any of the JavaScript libraries. Ruby is also a popular choice, so I would recommend checking that out too. For more scientific fields or areas with more machine learning and A.I., Python is generally a great place to start as it is widely used in that field of study. C++ is also a very useful language to know for that, but it can be a little more challenging for beginners. For game and application design, languages such as C#, C, Swift, Kotlin, and Java are most often used for that.
Description
According to Goldbach’s weak conjecture, every odd number greater than 5 can be expressed as the sum of three prime numbers. (A prime may be used more than once in the same sum.) This conjecture is called "weak" because if Goldbach's strong conjecture (concerning sums of two primes) is proven, it would be true. Computer searches have only reached as far as 1018 for the strong Goldbach conjecture, and not much further than that for the weak Goldbach conjecture.
In 2012 and 2013, Peruvian mathematician Harald Helfgott released a pair of papers that were able to unconditionally prove the weak Goldbach conjecture.
Your task today is to write a program that applies Goldbach's weak conjecture to numbers and shows which 3 primes, added together, yield the result.
Input Description
You'll be given a series of numbers, one per line. These are your odd numbers to target. Examples:
11
35
Output Description
Your program should emit three prime numbers (remember, one may be used multiple times) to yield the target sum. Example:
11 = 3 + 3 + 5
35 = 19 + 13 + 3
Challenge Input
111
17
199
287
53
Solution
in Python
def sixn(m):
"""All primes are of the form 6n + 1 or 6n - 1"""
yield from range(2, min(m, 3))
for i in range(6, m - 1, 6):
yield from (i - 1, i + 1)
if m > 8 and i + 5 < m:
yield i + 5
def primes_until(m):
"""(https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)"""
sieve = [True] * m
for i in sixn(int(sqrt(m)) + 1):
if sieve[i]:
for mult in range(i * i, m, i):
sieve[mult] = False
yield from (i for i in sixn(m) if sieve[i])
def solve(inp):
def weak_goldbach(n):
for p1 in primes:
if p1 >= n:
break
n1 = n - p1
for p2 in primes:
if p2 >= n1:
break
if n1 - p2 in primesSet:
return "%d + %d + %d" % (p1, p2, n1 - p2)
numbers = [int(i) for i in inp.splitlines()]
primes = list(primes_until(max(numbers)))
primesSet = set(primes)
return "\n".join(weak_goldbach(n) for n in numbers)
According to Goldbach’s weak conjecture, every odd number greater than 5 can be expressed as the sum of three prime numbers. (A prime may be used more than once in the same sum.) This conjecture is called "weak" because if Goldbach's strong conjecture (concerning sums of two primes) is proven, it would be true. Computer searches have only reached as far as 1018 for the strong Goldbach conjecture, and not much further than that for the weak Goldbach conjecture.
In 2012 and 2013, Peruvian mathematician Harald Helfgott released a pair of papers that were able to unconditionally prove the weak Goldbach conjecture.
Your task today is to write a program that applies Goldbach's weak conjecture to numbers and shows which 3 primes, added together, yield the result.
Input Description
You'll be given a series of numbers, one per line. These are your odd numbers to target. Examples:
11
35
Output Description
Your program should emit three prime numbers (remember, one may be used multiple times) to yield the target sum. Example:
11 = 3 + 3 + 5
35 = 19 + 13 + 3
Challenge Input
111
17
199
287
53
Solution
in Python
def sixn(m):
"""All primes are of the form 6n + 1 or 6n - 1"""
yield from range(2, min(m, 3))
for i in range(6, m - 1, 6):
yield from (i - 1, i + 1)
if m > 8 and i + 5 < m:
yield i + 5
def primes_until(m):
"""(https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)"""
sieve = [True] * m
for i in sixn(int(sqrt(m)) + 1):
if sieve[i]:
for mult in range(i * i, m, i):
sieve[mult] = False
yield from (i for i in sixn(m) if sieve[i])
def solve(inp):
def weak_goldbach(n):
for p1 in primes:
if p1 >= n:
break
n1 = n - p1
for p2 in primes:
if p2 >= n1:
break
if n1 - p2 in primesSet:
return "%d + %d + %d" % (p1, p2, n1 - p2)
numbers = [int(i) for i in inp.splitlines()]
primes = list(primes_until(max(numbers)))
primesSet = set(primes)
return "\n".join(weak_goldbach(n) for n in numbers)
Comments
Post a Comment