Problem 248. Twins in a Window

Twin primes are prime numbers that differ by 2, such as [11,13] or [41,43]. Write a function that returns a sorted list of the twin primes between lowVal and highVal (all the primes must be greater than lowVal and less than highVal). The primes should be arranged in an n-by-2 matrix as shown in the examples below.


 Input  lowVal = 10, highVal = 50
 Output p is [ 11    13
               17    19
               29    31
               41    43 ]
 Input  lowVal = 1000, highVal = 1050
 Output p is [ 1019  1021
               1031  1033 ]

Solution Stats

72.96% Correct | 27.04% Incorrect
Last solution submitted on Nov 04, 2016

Problem Comments


Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more