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

Challenge: fastest program wins

Name: Anonymous 2009-04-14 12:59

Write a program in your language that
1.opens a file as arbitrary precision integer.
2.divides the number by 3.
3.stores the binary result in another file.

Name: Anonymous 2009-04-18 5:40

#include <stdio.h>
/* change this to the largest multiple of your filesystem's
   blocksize that's less than available physical memory. */
#define BUF_LEN 1073741824
unsigned char buffa[BUF_LEN];
/* takes input from stdin file, writes output to stdout file */
main() {
 register unsigned char r = 0;
 register int i;
 while(i=fread(buffa,1,BUF_IN_LEN,stdin)) {
  register int j;
  for(j=0;j<i;i++) {
   register unsigned int d = (r<<8) + buffa[j];
   register unsigned char q = (d>>2) + (d>>4) + (d>>6) + (d>>8) + (d>>10) + (d>>12) + (d>>14);
   r = d - q - (q<<2);
   buffa[j] = q;
  }
  fwrite(buffa,1,i,stdout);
 }
 return 0;
}


Time this.

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