MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Twin primes are primes p1, p2 = p1 + 2 such that both p1 and p2 are prime numbers. Given a positive integer N (>=5) what are the largest twin primes (in order) <= N. For example, if N = 20 then p1 = 17 and p2 = 19.

83 correct solutions
34 incorrect solutions

Last solution submitted on Mar 20, 2015

2 Comments

Ryan
on 5 Dec 2012

Tim,
Can you explain what the +'01'-'0' is doing? I don't see how i+'01'-'0'=[i,i+1].
Thanks

J.R.! Menzinger
on 6 Dec 2012

'01 ' is a char vector of 2 positions: '0' ans '1'.
If you subtract '0' to it, it results a char vector with characters 0 and 1.
So '01'-'0' is the same as [0 1], but because of the '[]', it cost less operations.

1 Comment