3 deleted 243 characters in body
source | link

CJam, 2929 26 bytes

2q~Y4]{\{:)_2+mp1$mp&@-_{mp}h;"/&!}g}q~*", "1$2+"*
2q~Y4]        " Push [ 2 and4 the]. integer passed from STDIN (“N”).                                                       ";
{          "                                                                          ";
  \)_{        " Rotate 2 on top, increment it and duplicate the result.                  ";
  2+mp  " Push 1 if the copy plus 2 is a prime number; otherwise, push 0.          ";
  1$mp  " Push 1 if the copy is a prime number; otherwise, push 0.  ";
    :)     " Increment each integer in the array. ";
  &     " Compute the logical AND of the two previous integers.                    ";
  @-  _  " Rotate “N” on top" ofDuplicate the stackarray. and subtract it from the previous result. ";
}h      " If the modified “N” is non-zero, repeat the loop.                        ";
;      ";
  " Discard “N”{mp}/ (now zero)." For each integer in the array, push 1 if it's prime and 0 otherwise.     ";
    &!     " Compute the logical NOT of the bitwise AND of the two previous integers. ";  
  }g      ";
", " If the result "is Pushnon-zero, thatrepeat stringthe loop.                              ";
}q~*       " Do the above “N” times, where “N” is the integer read from STDIN.        ";
1$2+", "   " Push the prime number" plusJoin 2.the array by comma and space.                                       ";

Note that we should subtract the result of the logical AND from “N”, not vice versa. However, since the next number to tested will be even if the last was prime, the sign "fixes itself".

CJam, 29 bytes

2q~{\)_2+mp1$mp&@-}h;", "1$2+
2q~     " Push 2 and the integer passed from STDIN (“N”).                          ";
{       "                                                                          ";
  \)_   " Rotate 2 on top, increment it and duplicate the result.                  ";
  2+mp  " Push 1 if the copy plus 2 is a prime number; otherwise, push 0.          ";
  1$mp  " Push 1 if the copy is a prime number; otherwise, push 0.                 ";
  &     " Compute the logical AND of the two previous integers.                    ";
  @-    " Rotate “N” on top of the stack and subtract it from the previous result. ";
}h      " If the modified “N” is non-zero, repeat the loop.                        ";
;       " Discard “N” (now zero).                                                  ";
", "    " Push that string.                                                        ";
1$2+    " Push the prime number plus 2.                                            ";

Note that we should subtract the result of the logical AND from “N”, not vice versa. However, since the next number to tested will be even if the last was prime, the sign "fixes itself".

CJam, 29 26 bytes

Y4]{{:)_{mp}/&!}g}q~*", "*
Y4]        " Push [ 2 4 ].                                                            ";
{          "                                                                          ";
  {        "                                                                          ";
    :)     " Increment each integer in the array.                                     ";
    _      " Duplicate the array.                                                     ";
    {mp}/  " For each integer in the array, push 1 if it's prime and 0 otherwise.     ";
    &!     " Compute the logical NOT of the bitwise AND of the two previous integers. ";  
  }g       " If the result is non-zero, repeat the loop.                              ";
}q~*       " Do the above “N” times, where “N” is the integer read from STDIN.        ";
", "       " Join the array by comma and space.                                       ";
    Post Undeleted by Dennis
2 added 1141 characters in body
source | link
$ for i in {1..10}; do cjam twin-primes.cjam <<< 1;$i; echoecho; done
3, 5
$5, cjam7
11, twin-primes.cjam13
17, <<<19
29, 2;31
41, echo43
559, 761
$71, cjam73
101, twin-primes103
107, 109

How it works

2q~     " Push 2 and the integer passed from STDIN (“N”).cjam <<< 3; echo                       ";
11{       "                                                                          ";
  \)_   " Rotate 2 on top, 13increment it and duplicate the result.                  ";
$ cjam twin-primes2+mp  " Push 1 if the copy plus 2 is a prime number; otherwise, push 0.cjam <<< 4; echo       ";
17  1$mp  " Push 1 if the copy is a prime number; otherwise, 19push 0.                 ";
$ cjam twin&     " Compute the logical AND of the two previous integers.                    ";
  @-primes    " Rotate “N” on top of the stack and subtract it from the previous result.cjam <<<";
}h 5; echo    " If the modified “N” is non-zero, repeat the loop.                        ";
29;       " Discard “N” (now zero).                                                  ";
", 31"    " Push that string.                                                        ";
1$2+    " Push the prime number plus 2.                                            ";

Note that we should subtract the result of the logical AND from “N”, not vice versa. However, since the next number to tested will be even if the last was prime, the sign "fixes itself".

$ cjam twin-primes.cjam <<< 1; echo
3, 5
$ cjam twin-primes.cjam <<< 2; echo
5, 7
$ cjam twin-primes.cjam <<< 3; echo
11, 13
$ cjam twin-primes.cjam <<< 4; echo
17, 19
$ cjam twin-primes.cjam <<< 5; echo
29, 31
$ for i in {1..10}; do cjam twin-primes.cjam <<< $i; echo; done
3, 5
5, 7
11, 13
17, 19
29, 31
41, 43
59, 61
71, 73
101, 103
107, 109

How it works

2q~     " Push 2 and the integer passed from STDIN (“N”).                          ";
{       "                                                                          ";
  \)_   " Rotate 2 on top, increment it and duplicate the result.                  ";
  2+mp  " Push 1 if the copy plus 2 is a prime number; otherwise, push 0.          ";
  1$mp  " Push 1 if the copy is a prime number; otherwise, push 0.                 ";
  &     " Compute the logical AND of the two previous integers.                    ";
  @-    " Rotate “N” on top of the stack and subtract it from the previous result. ";
}h      " If the modified “N” is non-zero, repeat the loop.                        ";
;       " Discard “N” (now zero).                                                  ";
", "    " Push that string.                                                        ";
1$2+    " Push the prime number plus 2.                                            ";

Note that we should subtract the result of the logical AND from “N”, not vice versa. However, since the next number to tested will be even if the last was prime, the sign "fixes itself".

    Post Deleted by Dennis
1
source | link

CJam, 29 bytes

2q~{\)_2+mp1$mp&@-}h;", "1$2+

Try it online.

Examples

$ cjam twin-primes.cjam <<< 1; echo
3, 5
$ cjam twin-primes.cjam <<< 2; echo
5, 7
$ cjam twin-primes.cjam <<< 3; echo
11, 13
$ cjam twin-primes.cjam <<< 4; echo
17, 19
$ cjam twin-primes.cjam <<< 5; echo
29, 31