9
\$\begingroup\$

The Goldbach conjecture states that:

every even number that is greater than 2 is the sum of two primes.

We will consider a Goldbach partition of a number n to be a pair of two primes adding to n. We are concerned with numbers is of increasing Goldbach partition. We measure the size of a number's Goldbach partitions by the size of the smallest prime in all of that number's partitions. A number is of increasing partition if this size is greater than the size of all smaller even numbers.

Task

Given an even integer n > 2, determine if n is of increasing Goldbach partition, and output two unique values, one if it is and one if it is not.

This is , so you should aim to minimize the number of bytes in your source code.

OEIS A025018

\$\endgroup\$
5
  • \$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$
    – Wheat Wizard
    Jul 3, 2017 at 14:31
  • \$\begingroup\$ It is good question, that is difficult to understand. I edited it to simplify the wording. Please check it, and if all is correct apply changes. \$\endgroup\$ Jul 3, 2017 at 16:38
  • 1
    \$\begingroup\$ @ЕвгенийНовиков I found your edit more confusing than the original. I have rejected it. Perhaps we can discuss a way to make this clearer here. \$\endgroup\$
    – Wheat Wizard
    Jul 3, 2017 at 16:40
  • \$\begingroup\$ The worked examples are still very confusing - they seem to pull numbers out of nowhere, and each of the comparisons is expressed differently without explaining why certain numbers are used. If you already know the answer, you can figure it out . . . which I did by going back to the first paragraph, ignoring the examples until it was clear, then figuring out how the examples were constructed. Perhaps some tabular structure would help, also including 10 would probably help \$\endgroup\$ Jul 3, 2017 at 23:05
  • \$\begingroup\$ @NeilSlater Thanks for the feedback. I've removed the examples entirely because I think they were doing more harm than good. I think the challenge is clear from the explanation, and the examples only complicate things. If the explanation is not sufficient I would be more than happy to expand or clarify on that, however I don't think I will be adding the examples back in because they seem to be the greatest source of confusion so far. \$\endgroup\$
    – Wheat Wizard
    Jul 3, 2017 at 23:26

5 Answers 5

5
\$\begingroup\$

Jelly, 12 bytes

ÆRðfạṂ
Ç€M⁼W

Try it online!

How it works

Ç€M⁼W   Main link. Argument: n

Ç€      Map the helper link over [1, ..., n].
  M     Get all indices of the maximum.
    W   Wrap; yield [n].
   ⁼    Test the results to both sides for equality.


ÆRðfạṂ  Helper link. Argument: k

ÆR      Prime range; get all primes in R := [1, ..., k].
  ð     Begin a dyadic chain with arguments R and k.
    ạ   Absolute difference; yield k-p for each p in R.
   f    Filter; keep the q in R such that q = k-p for some p in R.
     Ṃ  Take the minimum.
        This yields 0 if the array is empty.
\$\endgroup\$
4
\$\begingroup\$

PHP, 154 bytes

for(;$n++<$a=$argn;$i-1?:$p[]=$n)for($i=$n;--$i&&$n%$i;);foreach($p as$x)foreach($p as$y)if(!$r[$z=$x+$y]){$r[$z]=$x;$l[]=$z<$a?$x:0;};echo$r[$a]>max($l);

Try it online!

Expanded

for(;$n++<$a=$argn;$i-1?:$p[]=$n) # loop through all integers till input if is prime add to array 
  for($i=$n;--$i&&$n%$i;);
foreach($p as$x) #loop through prime array
  foreach($p as$y) #loop through prime array 
    if(!$r[$z=$x+$y]){
      $r[$z]=$x; # add only one time lower value for a sum of $x+$y 
      $l[]=$z<$a?$x:0;}; # add lower value if sum is lower then input
echo$r[$a]>max($l); # Output 1 if lower value for sum of input is greater then all lower values of all numbers under input

Try it online! Check for all numbers till 1000

\$\endgroup\$
3
\$\begingroup\$

JavaScript (ES6), 135 bytes

Uses a similar logic as Jörg's PHP answer.

(n,P=[...Array(n).keys()].filter(n=>(p=n=>n%--x?p(n):x==1)(x=n)))=>P.map(p=>P.map(q=>a[q+=p]=a[q]||(m=q<n&&p>m?p:m,p)),a=[m=0])&&a[n]>m

Demo

let f =

(n,P=[...Array(n).keys()].filter(n=>(p=n=>n%--x?p(n):x==1)(x=n)))=>P.map(p=>P.map(q=>a[q+=p]=a[q]||(m=q<n&&p>m?p:m,p)),a=[m=0])&&a[n]>m

console.log(
  JSON.stringify(
    [...Array(310).keys()].filter(n => f(n))
  )
)

\$\endgroup\$
2
\$\begingroup\$

Python 3: 156 151 142 138 136 128 bytes

r=range
m=lambda n:min(x for x in r(2,n+1)if all(o%i for o in[x,n-x]for i in r(2,o)))
f=lambda n:m(n)>max(map(m,r(2,n,2)))or n<5

(thanks to OP)

(thanks to @Rod)(again)(and again)

\$\endgroup\$
7
  • \$\begingroup\$ @Olmman do you like it? \$\endgroup\$
    – enedil
    Jul 3, 2017 at 19:07
  • \$\begingroup\$ @Rod since max with key returns element with maximal value after applying key, I had to add function application but it's nonetheless shorter. \$\endgroup\$
    – enedil
    Jul 3, 2017 at 19:28
  • \$\begingroup\$ @Rod and I can't take your suggestions as for range since n is bounded inside lambda. \$\endgroup\$
    – enedil
    Jul 3, 2017 at 19:30
  • \$\begingroup\$ @enedil Indeed, but for the max, you can use max(map(m,r[::2])) \$\endgroup\$
    – Rod
    Jul 3, 2017 at 19:31
  • 1
    \$\begingroup\$ You don't need to name f and thus can save 2 bytes by removing the f=. \$\endgroup\$
    – Wheat Wizard
    Jul 3, 2017 at 23:44
1
\$\begingroup\$

Python 3: 204 196 bytes

Bytes saved thanks to: Olm Man

from itertools import*
m=lambda g:min([x for x in product([n for n in range(2,g)if all(n%i for i in range(2,n))],repeat=2)if sum(x)==g][0])
i=lambda g:1if all(m(g)>m(x)for x in range(4,g,2))else 0

Try it online!

\$\endgroup\$
3
  • 2
    \$\begingroup\$ A few tips, most builtin functions like min and all can take generators as arguments, this means min([...]) can be shortened to min(...) and the same with all. You also can get rid of some spaces, particularly the space in import * and any space after braces, I see you have one after range(g) and one before [i for i in ..., neither are necessary. \$\endgroup\$
    – Wheat Wizard
    Jul 3, 2017 at 16:53
  • \$\begingroup\$ ^That's awesome, I didn't know that \$\endgroup\$
    – bendl
    Jul 3, 2017 at 16:55
  • \$\begingroup\$ Also you can make your prime check a little shorter by changing it to all(n%i for i in range(2,g)), but you have to change range(g) to range(1,g) because this gives a false positive on 1. \$\endgroup\$
    – Wheat Wizard
    Jul 3, 2017 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.