Name: Anonymous 2011-09-26 14:42
Write a program which solves for and prints the first 30 titanic primes. The person who writes the most efficient program wins. Use any language you like.
print [10**999 + n for n in (7, 663, 2121, 2593, 3561, 4717, 5863, 9459, 11239, 14397, 17289, 18919, 19411, 21667, 25561, 26739, 27759, 28047, 28437, 28989, 35031, 41037, 41409, 41451, 43047, 43269, 43383, 50407, 51043, 52507)]
#include <stdio.h>
char titanic[30][6] = {
"00007", "00663", "02121", "02593", "03561", "04717",
"05863", "09459", "11239", "14397", "17289", "18919",
"19411", "21667", "25561", "26739", "27759", "28047",
"28437", "28989", "35031", "41037", "41409", "41451",
"43047", "43269", "43383", "50407", "51043", "52507",
};
int main(void) {
int i, j;
for (i = 0; i < 30; i++) {
putchar('1');
for (j = 0; j < 994; j++)
putchar('0');
putchar(titanic[i][0]);
putchar(titanic[i][1]);
putchar(titanic[i][2]);
putchar(titanic[i][3]);
putchar(titanic[i][4]);
putchar('\n');
}
return 0;
}$ time python 2.py 1>/dev/null
real 0m0.236s
user 0m0.140s
sys 0m0.030s
$ time ./titanic 1>/dev/null
real 0m0.069s
user 0m0.015s
sys 0m0.016s
#include <stdio.h>
#define W "0000000000"
#define X W W W W W W W "0"
#define Y X X
#define Z "\n1" Y Y Y Y Y Y Y
int main(void) {puts(Z"00007"Z"00663"Z"02121"Z"02593"Z"03561"Z"04717"Z"05863"Z"09459"Z"11239"Z"14397"Z"17289"Z"18919"Z"19411"Z"21667"Z"25561"Z"26739"Z"27759"Z"28047"Z"28437"Z"28989"Z"35031"Z"41037"Z"41409"Z"41451"Z"43047"Z"43269"Z"43383"Z"50407"Z"51043"Z"52507"); return 0;}
#!/bin/sh
cat <<END
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000663
...and so on; 4chan won't let me post my entire program :(...
END/root> time a
...
real 0m0.027s
user 0m0.004s
sys 0m0.000s
section .data
s: db "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007, ...", 0xa
len equ $ - s
section .text
mov eax, 4
mov ebx, 1
mov ecx, s
mov edx, len
int 0x80
mov eax, 1
mov ebx, 0
int 0x80[~/x86] time ./fastest > /dev/null
real 0m0.004s
user 0m0.000s
sys 0m0.004s
mov eax, 4
inc ebx
mov ecx, s
mov edx, len
int 0x80
mov eax, 1
dec ebx
int 0x80
/* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program starts %edx
contains a pointer to a function which might be registered using `atexit'.
This provides a mean for the dynamic linker to call DT_FINI functions for
shared libraries that have been loaded before the code runs.
A value of 0 tells we have no such handler.
We might as well make sure everything else is cleared too (except for %esp),
just to make things more deterministic.
*/
#define ELF_PLAT_INIT(_r, load_addr) \
do { \
_r->bx = 0; _r->cx = 0; _r->dx = 0; \
_r->si = 0; _r->di = 0; _r->bp = 0; \
_r->ax = 0; \
} while (0)