for n =10,p1=[3 5 7],p2=[7 5 3],is the correct answer. but the judgement is not allowed.
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.
for i = 1:5000
x1 = ceil(286*rand(1));
x2 = ceil(286*rand(1));
s = x1+x2;
if a==1 && b==1 && s ==n
Really interesting the Goldbach conjecture!
At first,I thought I should find all the possible answers.But I misunderstood the text............
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
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?
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);
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);
smart and short... i needed a "few" lines more :-)
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.
Find the sum of the elements in the "second" diagonal
Do you like your boss?
Sum of the Matrix Elements
Draw a 'X'!
Implement a ROT13 cipher
Word Counting and Indexing
Which values occur exactly three times?
Determine whether a vector is monotonically increasing
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office