Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ Challenge

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.

Name: Anonymous 2011-09-26 14:57

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)]

Name: Anonymous 2011-09-26 15:09

I don't even know what titanic prime is and I'm too lazy to find out. You should make better challenge.

Name: 2 2011-09-26 15:13

>>3
And I want my prize.

Name: Anonymous 2011-09-26 15:14

>>2
I am pretty sure doing this in assembly would be more efficient, but you have the right idea.

Name: Anonymous 2011-09-26 15:15

>>5
My program is still the most efficient submission, I want my prize.

Name: Anonymous 2011-09-26 15:31

#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;
}


Timing (compiled mine with -O3):
$ 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

Name: >>7 2011-09-26 16:12

Well, it's faster to just print a large string, it seems.

#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;}

Name: Anonymous 2011-09-26 19:47

#!/bin/sh
cat <<END
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000663

...and so on; 4chan won't let me post my entire program :(...

END


Timing:
/root> time a

...

real    0m0.027s
user    0m0.004s
sys    0m0.000s

Name: Anonymous 2011-09-26 19:47

>>9
BTW, I won.

Name: sage 2011-09-26 19:53

>>8

This is pretty awesome. You could just refactor it a bit.

For example, no need for "return 0" in main (don't worry, it's standard), neither return type, neither argument list. Also, maybe break lines at the Zs.

Name: Anonymous 2011-09-26 21:01

>>11

Are you retarded?

Name: 2 2011-09-26 21:28

This is the fastest, yours are slower because they're line buffered coupled with some bloated C library, mine is fully buffered. I had to replace the next titanic primes with nothing for posting purposes.

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


The full program (with all the 30 first titanic primes) exited successfully.

[~/x86] time ./fastest > /dev/null

real    0m0.004s
user    0m0.000s
sys    0m0.004s

Name: sage 2011-09-26 23:31

>>13
Not fast enough. All registers start up zeroed, and an inc is faster than a mov immediate.


mov eax, 4
inc ebx
mov ecx, s
mov edx, len
int 0x80

mov eax, 1
dec ebx
int 0x80


Faster by tenths of nanoseconds.

Name: Anonymous 2011-09-27 0:39

If this were measured from htting <ENTER> to run program, you'd have to count time to load from disk.

Name: Anonymous 2011-09-27 0:52

My operating system is way faster -- INT is slow.  LoseThos is all ring-0.

Name: Anonymous 2011-09-27 3:46

>>16
It's faster, but it's also shit.

Name: Anonymous 2011-09-27 7:09

>>14
All registers start up zeroed
That's not even close to true.

Name: Anonymous 2011-09-27 9:29

>>17
U MENA dIARRHEA?

Name: sage 2011-09-27 11:51

>>18
/usr/src/linux-2.6.39/arch/x86/include/asm/elf.h:

/* 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)

It happens to be. Sorry. You're a bad troll.

Name: Anonymous 2011-09-27 13:10

>>20
Are you trolling are or you just immensely stupid?

Name: sage 2011-09-27 15:47

>>21

Actually, you're the one who should answer that question.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List