for n =10,p1=[3 5 7],p2=[7 5 3],is the correct answer. but the judgement is not allowed.
Nice one.
Thank you very much! Its a really nice one!
Well made. I am still trimming down my code furiously. My favorite problem so far.
Currently the best one for me!
nice problem . I like problem related to prime numbers
Very nice problem!
this was a fun one
something I am doing worng.
please help.
p1=[]
p2=[]
for i = 1:5000
x1 = ceil(286*rand(1));
x2 = ceil(286*rand(1));
s = x1+x2;
a =isprime(x1);
b=isprime(x2);
if a==1 && b==1 && s ==n
p1=x1
p2=x2
end
end
[p1 p2]
cool
有中国的小伙伴吗？
Really interesting the Goldbach conjecture!
有中国的小伙伴呀
At first,I thought I should find all the possible answers.But I misunderstood the text............
nice question
perfect nice
Happier now. Loop though nList handled in test suite. No loop in my function and returns the 2 primes closest together
given that the looping through nList is handled in the test suite, I don't need to.
returning single value of prime pair instead of vector will help
with functions like nchoosek and primes, it is quite easy
tai tama nan le.:)
Forgetting 1 isn't prime doesn't help
See https://en.wikipedia.org/wiki/Prime_number#Primality_of_one
my solution is correct,, what is the problem
Problem is with the test suite it expects just 2 numbers and you generated vector of all possible solutions, if you return after finding the first pair it will work.
Lists all of them.
High score but simple and two lines.
Can't use combnk()? Getting an error for using?
Oh, I can use nchoosek() instead...
Bizarrely I couldn't submit this solution when b, b1 and b2 were labelled p, p1 and p2 due to 'inappopriate content'. I'd be interested to know what looked so inappropriate...
Why is this not working?
how nice
n - (1:n) can be written as (n-1):-1:0
This one passed tests, but solves another problem: p1 is odd and p2 is prime. It fails to find 2+2=4 and finds incorrectly 9+89=98.
This is the best I can do...
Although the naming of primes is a poor choice,
primes = primes(nums);
can replace:
nums=2:n;
primes=nums(isprime(nums));
Although it passes the test suite, this solution is incorrect for n = 4, 6. The main reason for this error is that the nested loop for j is incorrect. It should be for j=i:c
It would be interesting that the test suite does the assertion on all entries of p1 & p2 in case they return all possible solutions.
assert(all(isprime(p1) & isprime(p2) & (p1+p2==n))
This is a very interesting approach to the problem - learned something new today :D.
I dont understand what the problem with solution is ?
Your for loop bounds exceed the number of prime factors of n. Also, it looks like you are solving for the stated case n=286 and the test cases are using additional inputs.
To compute all possible.. replace b=find(isprime(p2),1,'first'); with b=isprime(p2);
enjoy
smart and short... i needed a "few" lines more :-)
smart!
Shouldn't pass, but does. No check of both numbers being primenumbers
I see your point. You were lucky with the original test suite, but I've added a few more test points. Thanks.
Nice! I didn't know they have a function for C_n^k before.
Sometimes vectorized code is not the shortest.
379 Solvers
408 Solvers
460 Solvers
592 Solvers
392 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!