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

Pages: 1-4041-8081-120121-160161-

1000 factorial

Name: Anonymous 2011-04-02 22:59

Well, someone wrote that they could write a program to do 1000! in one line of Haskell. I said that it would take less than 100 lines of C to do the same. I wrote the program, and it is less than 100 lines of C:

#include <stdio.h>
#include <string.h>

#define LENGTH 10000

int max (int a, int b) { return (a > b) ? a : b; }
int min (int a, int b) { return (b > a) ? a : b; }

int length (unsigned char * a)
 {
   int i;
   i = LENGTH - 1;
   while ((a[i] == 0) && (i >= 0)) i--;
   return i + 1;
 }

void add (unsigned char * a, unsigned char * b)
 {
   int i, c, C;
   c = min(max(length(a), length(b)) + 1, LENGTH);
   for (i = 0, C = 0; i < c; i++)
    {
      a[i] += b[i] + C;
      C = a[i] > 99;
      if (C) a[i] -= 100;
    }
 }

   unsigned char x [LENGTH], y [LENGTH];
void mul (unsigned char * a, unsigned char * b)
 {
   int i, j, c, d, C;
   memset(y, '\0', LENGTH);
   c = min(length(a) + length(b) + 1, LENGTH);
   d = length(b);
   for (i = 0; i < d; i++)
    {
      memset(x, '\0', LENGTH);
      for (j = 0, C = 0; (i + j) < c; j++)
       {
         x[i + j] = (a[j] * b[i] + C) % 100;
         C = (a[j] * b[i] + C) / 100;
       }
      add(y, x);
    }
   memcpy(a, y, LENGTH);
 }

void numset (unsigned char * a, unsigned long b)
 {
   int i;
   for (i = 0; i < LENGTH; i++)
    {
      a[i] = b % 100;
      b /= 100;
    }
 }

int tz (unsigned char * a)
 {
   int i;
   for (i = 0; i < LENGTH; i++) if (a[i] != 0) return 0;
   return 1;
 }

   unsigned char minus1 [LENGTH], prod [LENGTH];
void fact (unsigned char * a)
 {
   numset(prod, 1);
   while (!tz(a))
    {
      mul(prod, a);
      add(a, minus1);
    }
   memcpy(a, prod, LENGTH);
 }

   unsigned char arg_res [LENGTH];
int main (void)
 {
   unsigned long a;
   int i;
   memset (minus1, 99, LENGTH);
   printf("Input the number to take the factorial of: ");
   scanf("%lu", &a);
   numset(arg_res, a);
   fact(arg_res);
   i = LENGTH - 1;
   while (arg_res[i] == 0) i--;
   while (i >= 0)
    {
      printf("%02d", (int) arg_res[i]);
      i--;
    }
   putchar('\n');
   return 0;
 }

Name: Anonymous 2011-04-02 23:01

>>1
... Wow. It's even worsebetter than mine[1].

[1] http://dis.4chan.org/read/prog/1296932382/5

Name: Anonymous 2011-04-02 23:07

From my calculator:
4.02387260077093773543702433923e+2567

The thought that I would ever have use for a number this great confounds my little brain.

Name: Anonymous 2011-04-02 23:09

'\0'

Name: Anonymous 2011-04-02 23:09

>>3
402387260077093773543702433923003985719374864210714632543799910429938512398629020592044208486969404800479988610197196058631666872994808558901323829669944590997424504087073759918823627727188732519779505950995276120874975462497043601418278094646496291056393887437886487337119181045825783647849977012476632889835955735432513185323958463075557409114262417474349347553428646576611667797396668820291207379143853719588249808126867838374559731746136085379534524221586593201928090878297308431392844403281231558611036976801357304216168747609675871348312025478589320767169132448426236131412508780208000261683151027341827977704784635868170164365024153691398281264810213092761244896359928705114964975419909342221566832572080821333186116811553615836546984046708975602900950537616475847728421889679646244945160765353408198901385442487984959953319101723355556602139450399736280750137837615307127761926849034352625200015888535147331611702103968175921510907788019393178114194545257223865541461062892187960223838971476088506276862967146674697562911234082439208160153780889893964518263243671616762179168909779911903754031274622289988005195444414282012187361745992642956581746628302955570299024324153181617210465832036786906117260158783520751516284225540265170483304226143974286933061690897968482590125458327168226458066526769958652682272807075781391858178889652208164348344825993266043367660176999612831860788386150279465955131156552036093988180612138558600301435694527224206344631797460594682573103790084024432438465657245014402821885252470935190620929023136493273497565513958720559654228749774011413346962715422845862377387538230483865688976461927383814900140767310446640259899490222221765904339901886018566526485061799702356193897017860040811889729918311021171229845901641921068884387121855646124960798722908519296819372388642614839657382291123125024186649353143970137428531926649875337218940694281434118520158014123344828015051399694290153483077644569099073152433278288269864602789864321139083506217095002597389863554277196742822248757586765752344220207573630569498825087968928162753848863396909959826280956121450994871701244516461260379029309120889086942028510640182154399457156805941872748998094254742173582401063677404595741785160829230135358081840096996372524230560855903700624271243416909004153690105933983835777939410970027753472000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Name: Anonymous 2011-04-03 1:57

here it OP, also a one-liner

printf("402387260077093773543702433923003985719374864210714632543799910429938512398629020592044208486969404800479988610197196058631666872994808558901323829669944590997424504087073759918823627727188732519779505950995276120874975462497043601418278094646496291056393887437886487337119181045825783647849977012476632889835955735432513185323958463075557409114262417474349347553428646576611667797396668820291207379143853719588249808126867838374559731746136085379534524221586593201928090878297308431392844403281231558611036976801357304216168747609675871348312025478589320767169132448426236131412508780208000261683151027341827977704784635868170164365024153691398281264810213092761244896359928705114964975419909342221566832572080821333186116811553615836546984046708975602900950537616475847728421889679646244945160765353408198901385442487984959953319101723355556602139450399736280750137837615307127761926849034352625200015888535147331611702103968175921510907788019393178114194545257223865541461062892187960223838971476088506276862967146674697562911234082439208160153780889893964518263243671616762179168909779911903754031274622289988005195444414282012187361745992642956581746628302955570299024324153181617210465832036786906117260158783520751516284225540265170483304226143974286933061690897968482590125458327168226458066526769958652682272807075781391858178889652208164348344825993266043367660176999612831860788386150279465955131156552036093988180612138558600301435694527224206344631797460594682573103790084024432438465657245014402821885252470935190620929023136493273497565513958720559654228749774011413346962715422845862377387538230483865688976461927383814900140767310446640259899490222221765904339901886018566526485061799702356193897017860040811889729918311021171229845901641921068884387121855646124960798722908519296819372388642614839657382291123125024186649353143970137428531926649875337218940694281434118520158014123344828015051399694290153483077644569099073152433278288269864602789864321139083506217095002597389863554277196742822248757586765752344220207573630569498825087968928162753848863396909959826280956121450994871701244516461260379029309120889086942028510640182154399457156805941872748998094254742173582401063677404595741785160829230135358081840096996372524230560855903700624271243416909004153690105933983835777939410970027753472000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");

Name: Anonymous 2011-04-03 2:11

New challenge: Write the shortest C program that outputs the factorial of 1000.

Deadline: 2011-04-17

Prize: 10 Susscoins, to be delivered via Sussmail

Name: Anonymous 2011-04-03 3:06

>>7
#include <stdio.h>
#include <gmp.h>
main(){mpz_t a;int b=1001;mpz_init_set_ui(a,1);while(--b)mpz_mul_ui(a,a,b);mpz_out_str(stdout,10,a);}

Name: Anonymous 2011-04-03 3:20

>>8
main(){system("dc -e '1000[d1-d1<F*]dsFxp'");}

Name: Anonymous 2011-04-03 7:25

#! /usr/bin/python

__import__("sys").setrecursionlimit(1002)

def fac(n): return n * fac(n-1) if n else 1

print fac(1000)

Name: Anonymous 2011-04-03 8:20

>>10
>>7
shortest C program
Your shitty, long[1] phyok program is not valid.

[1]
(define (f n) (if (zero? n) 1 (* n (f (sub1 n)))))
(f 1000)

Name: Anonymous 2011-04-03 9:33

>>11
Not tail recursive.

(define (f n) (let loop ([n n] [i 1]) (if (= n 0) i (loop (sub1 n) (* i n)))))
(f 1000)

Name: Anonymous 2011-04-03 10:41

>>12
Not OMG OPTIMIZED

(define small-odd-swing
  (vector 1 1 1 3 3 15 5 35 35 315 63 693 231 3003 429 6435 6435 109395
          12155 230945 46189 969969 88179 2028117 676039 16900975 1300075
          35102025 5014575 145422675 9694845 300540195 300540195))

(define (swing n)
  (if (< n 33) (vector-ref small-odd-swing n)
      (let* ((primes (sieve (range 3 n #:by 2)))
             (rootn (integer-sqrt n))
             (primesa (take-while (curryr <= rootn) primes))
             (primesb (filter (λ (x) (odd? (quotient n x)))
                                 (take-while (curryr <= (quotient n 3))
                                             (drop-while (curryr <= rootn) primes)))))
        (apply
         *
         (append
          (map
           (λ (prime)
             (do ((q (quotient n prime) (quotient q prime))
                  (p 1 (if (odd? q) (* p prime) p)))
               ((zero? q) p)))
           primesa)
          (take-while (curryr <= n)
                      (drop-while (curryr <= (quotient n 2)) primes))
          primesb)))))

(define (rec-fact n)
  (if (< n 2) 1
      (* (expt (rec-fact (quotient n 2)) 2) (swing n))))

(define (fact n)
  (if (< n 20) (Π values 1 n)
      (arithmetic-shift (rec-fact n) (- n (bitwise-bit-count n)))))
(fact 1000)

Name: Anonymous 2011-04-03 11:55

>>13
That's... optimized?

Name: Anonymous 2011-04-03 12:05

>>14
Yes it is.

; just for reference, Π is:
#;
(define (Π f n m #:threads (c (processor-count)))
  (let* ((t (lambda (a)
              (lambda ()
                (let/ec k
                  (do ((x (+ n a) (+ x c))
                       (r 1 (* r (f x))))
                    ((> x m) (k r)))))))
         (xs (do ((x (sub1 c) (sub1 x))
                  (xs '() (cons (future (t x)) xs)))
               ((zero? x) xs)))
         (x ((t 0))))
    (foldr * x (map touch xs))))

(define (naive-fact n)
  (Π values 1 n))

(collect-garbage)
(time (void (fact 100000)))
(collect-garbage)
(time (void (naive-fact 100000)))

; cpu time: 1030 real time: 1029 gc time: 520
; cpu time: 21552 real time: 21551 gc time: 7063

Name: Anonymous 2011-04-03 13:12


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int digits(int n)
{
    int digs = 0;
    for(;n!=0;n/=100) ++digs;
    return digs;
}

int mul(unsigned int len, unsigned char **num, unsigned int n)
{
    unsigned int rem = 0, i;
    for(i=0; i<len; i++) {
        unsigned int tmp = (*num)[i]*n + rem;
        (*num)[i] = tmp % 100;
        rem = tmp / 100;
    }
    if(rem!=0) {
        int addLen = digits(rem)+10;
        if((*num=realloc(*num, len+addLen))==NULL)
            return -1;      
        memset(&(*num)[len], 0, addLen);
        for(i=len; i<len+addLen; i++) {
            unsigned int tmp = (*num)[i]*n + rem;
            (*num)[i] = tmp % 100;
            rem = tmp / 100;
        }
        len += addLen;
    }
    return len;
}

int main() {
    unsigned int i, len=1000, factOf=100000;
    unsigned char *num = (unsigned char*)malloc(len*sizeof(unsigned char));
    memset(num, 0, len);
    num[0]=1;
    for(i=1; i<=factOf; i++)
        if ((len = mul(len, &num, i)) == -1) {
            printf("Hurrrr\n");
            return -1;
        }
    i = len;
    while(i--) printf("%02d", num[i]);
    putchar('\n');
    return 0;
}

real    0m41.340s
user    0m41.264s
sys     0m0.014s

Name: Anonymous 2011-04-03 14:43

>>16
real    0m41.340s
in >>15, those are milliseconds. It's 1.030s and 21.552s.

Name: Anonymous 2011-04-03 15:08

>>17
My levels of autism are not high enough.

Name: Anonymous 2011-04-03 15:13

>>18
C confirmed for RUBY AS FUCK

Name: Challenge Status 2011-04-03 16:16

>>8 is a cheapo for using a bignum library. His entry will be downgraded.

>>9 is cheating.

>>10 doesn't seem to know the difference between C and Python.

>>11-12 seems to be confusing programming languages as well.

>>13,15 is an expert Scheme programer, but doesn't seem to know the difference between C and Scheme. I'd give it the most interesting implementation award, however.

>>16 qualifies.

>>17 >>7 doesn't say anything about performance.

Name: Anonymous 2011-04-03 16:38

>>11,20

I'm calling it right now, you guys are fucking morons, it wasn't a response to your retarded little SEE challenge, it was a response to the original post. It even runs faster than your pathetic entries, if you're writing C at least do it right.

Name: Anonymous 2011-04-03 16:40

>>21
Calm down, bro.

Name: Anonymous 2011-04-03 16:59

>>20
>>1 is good enough, without using a bignum library. We'd just reimplement it over and over. I'd say this should be a ``make a fast/complete C bignum library'' challenge.

Name: Anonymous 2011-04-03 17:05

Name: Anonymous 2011-04-03 22:54

>>16
OP here. Nice. The math is problem specific, and faster for it.
>>21
Also, nice. You took a language which you wrote factorial in one line, and wrote it in alot of lines, and showed that version to be superior. How the hell does it work?

You have to be smarter than the language. How many C programmers can do ad hoc bignum math that does more than addition and subtraction? How many Scheme programmers can write >>13 ?

Name: Anonymous 2011-04-03 23:49

>>25
>>21
I'm not the deluded pythonista! I'm usually respectful, and knew that >>13 is not a valid entry.
I tried to do it in C, and wanted to make the bignum part faster, smaller (using a whole uintmax) and general, but it seems I can't write C code anymore. I give up, it would be much easier in Assembly.

What I've done so far:

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>

#define SIZE(sz) (sizeof(uintmax_t)*(sz))

typedef struct {
     uintmax_t *val;
     size_t len;
} bignum;

static inline max (size_t a, size_t b) {return a>b?a:b;}
static inline min (size_t a, size_t b) {return a<b?a:b;}

bignum *bignum_alloc(size_t sz) {
     bignum *n = malloc(sizeof(bignum));
     n->len = sz;
     n->val = malloc(SIZE(sz));
     return n;
}

bignum *bignum_copy(bignum *n) {
     bignum *m = bignum_alloc(n->len);
     memcpy(m->val, n->val, n->len);
     return m;
}

void bignum_realloc(bignum *n, size_t sz, uintmax_t val) {
     size_t oldsz = n->len;
     n->val = realloc(n->val, SIZE(sz));
     n->len = sz;
     n->val[oldsz] = val;
     if (oldsz < sz-1)
      memset(n+oldsz, 0, oldsz+1);
}

void bignum_dealloc(bignum *n) {
     free(n->val);
     free(n);
}

bignum *bignum_from_uintmax(uintmax_t n) {
     bignum *m = bignum_alloc(1);
     m->val[0] = n;
     return m;
}

void bignum_addbi(bignum *n, uintmax_t m) {
     size_t i, j = n->len;
     uintmax_t a;

     for (a = n->val[i], i = 0; m && i < j; i++) {
      a = n->val[i];
      n->val[i] += m;
      m = a > n->val[i];
     }
     if (m && i >= n->len)
      bignum_realloc(n, n->len+1, 1);
}


void bignum_addbb(bignum *n, bignum *m) {
     size_t i, j = max(n->len, m->len);
     uintmax_t a; int c;
     if (n->len < m->len)
      bignum_realloc(n, m->len, 0);
     for (i = 0, c = 0; i < j; i++) {
      a = n->val[i];
      n->val[i] += m->val[i] + c;
      c = a > n->val[i];
     }
     if (c && i >= j++)
      bignum_realloc(n, j, 1);
}

void bignum_subbi(bignum *n, uintmax_t m) {
     size_t i, j = n->len;
     uintmax_t a;

     for (a = n->val[i], i = 0; m && i < j; i++) {
      a = n->val[i];
      n->val[i] -= m;
      m = a < n->val[i];
     }
     if (--j && !n->val[j])
      bignum_realloc(n, j, n->val[j]);
}

void bignum_mulbb(bignum *n, bignum *m) {
     if (bignum_zerop(m)) {
      bignum_dealloc(n);
      n = bignum_from_uintmax(0);
     }
     if (bignum_equalpi(m, 1)) return;
     bignum *i = bignum_copy(m);
     bignum *l = bignum_copy(n);
     for (; !bignum_equalpi(i, 1); bignum_subbi(i, 1))
      bignum_addbb(n, l);
     bignum_dealloc(i);
     bignum_dealloc(l);
}

void bignum_mulbi(bignum *n, uintmax_t m) {
     if (!m) {
      bignum_dealloc(n);
      n = bignum_from_uintmax(0);
     }
     if (m == 1) return;
     bignum *l = bignum_copy(n);
     while (--m)
      bignum_addbb(n, l);
}

int bignum_zerop(bignum *n) {
     return (!(!(n->len-1) && n->val[0]));
}

int bignum_equalp(bignum *n, bignum *m) {
     if (n->len != m->len) return 0;
     size_t i = n->len;
     while (n->val[i] == m->val[i]) i--;
     return !!i;
}

inline int bignum_equalpi(bignum *n, uintmax_t m) {
     return (!(n->len > 1)) && (n->val[0] == m);
}

void debug_print_bn(bignum *n) {
     printf("Memory Location: %#08x; %#08x\n", n, n->val);
     printf("Length: %u\n", n->len);
     size_t i;
     for (i = 0; i < n->len; i++)
      printf("Cell#%08u: %016llx\n", i, n->val[i]);
}

Name: Anonymous 2011-04-04 1:29

>>26
OVER 9000 REALLOC OPERATION
REWRITE THAT SHIT

Name: Anonymous 2011-04-04 1:39

Or the weenie can learn to write proper code using a functional programming language like Haskell.

Name: Anonymous 2011-04-04 1:44

>>27
I will not, I fucking hate writing C and managing memory.

Name: Anonymous 2011-04-04 4:28

Listen to >>27-san, >>29-kun.

Name: Anonymous 2011-04-04 5:45

>>26
Is it me, or does that look like GNU bc code?
>>21
You can call me a fucking retard when you post a portable multithreaded FFT multiplication implementation that's one shot for a factorial program. I'm not a retard just because Scheme holds your little hand and hides the machine from you.

Name: Anonymous 2011-04-04 13:18

>>31
Shit, am I that bad? I've never seen GNU bc's code.

>>21
Scheme

I am the Schemer, that was the deluded pythonista troll. I'm aware I suck at C.

Also バンパ·チャレンジ.

Name: Anonymous 2011-04-04 13:33

>>32
``バンパ''?

Name: Anonymous 2011-04-04 14:06

>>33
Typo. *バンプ.

Name: Anonymous 2011-04-04 14:10

>>32
suck my cock faggot

Name: Anonymous 2011-04-04 14:41

>>32
Well, sorry. I still need to try to wrap my head around what that code does. What is a "Bumper Challenge" (according to Google Translate)?

Name: Anonymous 2011-04-04 15:22

>>36
It does prime factorization, and basically is a faster version of

(define (factor x p)
  (let loop ((x (quotient x p))
             (r 0))
    (if (< x 2) (+ x r)
        (loop (quotient x p)
              (+ x r)))))

(define (prime-factorization x)
  (let ((primes (sieve (cons 2 (range 3 x #:by 2)))))
    (map expt primes (map (λ (p) (factor x p)) primes))))

(apply * (prime-factorization 5)) ; => 120


I'm not exactly sure of how swing exactly works, and the rec-fact thing seems to be there to make it run in logarithmic time. The bit-count thing is a mystery too.
I'm still trying to understand it too.

Name: Anonymous 2011-04-05 14:30

pump

Name: Anonymous 2011-04-05 15:33

    ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
    █     ___                        █
    █    //  7                       █
    █   (_,_/\       WORSHIP THIS    █
    █    \    \   YOUR THROBBING GOD █
    █     \    \                     █
    █     _\    \__                  █
    █    (   \     )                 █
    █     \___\___/                  █
    █                                █
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

Name: Anonymous 2011-04-05 15:33

    ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
    █     ___                        █
    █    //  7                       █
    █   (_,_/\       WORSHIP THIS    █
    █    \    \   YOUR THROBBING GOD █
    █     \    \                     █
    █     _\    \__                  █
    █    (   \     )                 █
    █     \___\___/                  █
    █                                █
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

Name: Anonymous 2011-04-05 15:33

    ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
    █     ___                        █
    █    //  7                       █
    █   (_,_/\       WORSHIP THIS    █
    █    \    \   YOUR THROBBING GOD █
    █     \    \                     █
    █     _\    \__                  █
    █    (   \     )                 █
    █     \___\___/                  █
    █                                █
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

Name: Anonymous 2011-04-05 15:33

    ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
    █     ___                        █
    █    //  7                       █
    █   (_,_/\       WORSHIP THIS    █
    █    \    \   YOUR THROBBING GOD █
    █     \    \                     █
    █     _\    \__                  █
    █    (   \     )                 █
    █     \___\___/                  █
    █                                █
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

Name: Anonymous 2011-04-05 15:33

    ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
    █     ___                        █
    █    //  7                       █
    █   (_,_/\       WORSHIP THIS    █
    █    \    \   YOUR THROBBING GOD █
    █     \    \                     █
    █     _\    \__                  █
    █    (   \     )                 █
    █     \___\___/                  █
    █                                █
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

Name: Anonymous 2011-04-05 15:33

    ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
    █     ___                        █
    █    //  7                       █
    █   (_,_/\       WORSHIP THIS    █
    █    \    \   YOUR THROBBING GOD █
    █     \    \                     █
    █     _\    \__                  █
    █    (   \     )                 █
    █     \___\___/                  █
    █                                █
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

Name: Anonymous 2011-04-05 15:36

    ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
    █     ___                        █
    █    //  7                       █
    █   (_,_/\       WORSHIP THIS    █
    █    \    \   YOUR THROBBING GOD █
    █     \    \                     █
    █     _\    \__                  █
    █    (   \     )                 █
    █     \___\___/                  █
    █                                █
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

Name: Anonymous 2011-04-05 15:36

>>39-44
This is why I hate little kids.

Name: PUDDI 2011-04-05 16:07

PUDDI

Name: PUDDI 2011-04-05 17:02

>>46
fuck off and die faggot

Name: Anonymous 2011-04-05 17:10

>>47-48
Summer is near.

Name: Anonymous 2011-04-05 17:29

>>49
I think I'm going to run the Anusbot for three months non-stop.

Name: Anonymous 2011-04-05 17:32

>>50
How about complaining about the current status of /prog/ with MrVacBob-sama-kun-san? It doesn't work.

Name: Anonymous 2011-04-05 22:53

>>50
lolol progfag y u dont just go fuck urself cuz noone else is going2 lmao

Name: Anonymous 2011-04-06 0:08

>>50-51
ur lisp move but all i can hear is "im a huge faggot please rape my face" -u

Name: Anonymous 2011-04-06 9:50

One line.  I win.

[code]
#include <iostream>

main() {cout << "402387260077093773543702433923003985719374864210714632543799910429938512398629020592044208486969404800479988610197196058631666872994808558901323829669944590997424504087073759918823627727188732519779505950995276120874975462497043601418278094646496291056393887437886487337119181045825783647849977012476632889835955735432513185323958463075557409114262417474349347553428646576611667797396668820291207379143853719588249808126867838374559731746136085379534524221586593201928090878297308431392844403281231558611036976801357304216168747609675871348312025478589320767169132448426236131412508780208000261683151027341827977704784635868170164365024153691398281264810213092761244896359928705114964975419909342221566832572080821333186116811553615836546984046708975602900950537616475847728421889679646244945160765353408198901385442487984959953319101723355556602139450399736280750137837615307127761926849034352625200015888535147331611702103968175921510907788019393178114194545257223865541461062892187960223838971476088506276862967146674697562911234082439208160153780889893964518263243671616762179168909779911903754031274622289988005195444414282012187361745992642956581746628302955570299024324153181617210465832036786906117260158783520751516284225540265170483304226143974286933061690897968482590125458327168226458066526769958652682272807075781391858178889652208164348344825993266043367660176999612831860788386150279465955131156552036093988180612138558600301435694527224206344631797460594682573103790084024432438465657245014402821885252470935190620929023136493273497565513958720559654228749774011413346962715422845862377387538230483865688976461927383814900140767310446640259899490222221765904339901886018566526485061799702356193897017860040811889729918311021171229845901641921068884387121855646124960798722908519296819372388642614839657382291123125024186649353143970137428531926649875337218940694281434118520158014123344828015051399694290153483077644569099073152433278288269864602789864321139083506217095002597389863554277196742822248757586765752344220207573630569498825087968928162753848863396909959826280956121450994871701244516461260379029309120889086942028510640182154399457156805941872748998094254742173582401063677404595741785160829230135358081840096996372524230560855903700624271243416909004153690105933983835777939410970027753472000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";}

Name: Anonymous 2011-04-06 10:13

Can you write one that does this within 1000! lines of brainfuck?

Name: Anonymous 2011-04-06 10:50

>>55
you fucked up your post, check your semantics

Name: Anonymous 2011-04-06 11:29

>>55
402387260077093773543702433923003985719374864210714632543799910429938512398629020592044208486969404800479988610197196058631666872994808558901323829669944590997424504087073759918823627727188732519779505950995276120874975462497043601418278094646496291056393887437886487337119181045825783647849977012476632889835955735432513185323958463075557409114262417474349347553428646576611667797396668820291207379143853719588249808126867838374559731746136085379534524221586593201928090878297308431392844403281231558611036976801357304216168747609675871348312025478589320767169132448426236131412508780208000261683151027341827977704784635868170164365024153691398281264810213092761244896359928705114964975419909342221566832572080821333186116811553615836546984046708975602900950537616475847728421889679646244945160765353408198901385442487984959953319101723355556602139450399736280750137837615307127761926849034352625200015888535147331611702103968175921510907788019393178114194545257223865541461062892187960223838971476088506276862967146674697562911234082439208160153780889893964518263243671616762179168909779911903754031274622289988005195444414282012187361745992642956581746628302955570299024324153181617210465832036786906117260158783520751516284225540265170483304226143974286933061690897968482590125458327168226458066526769958652682272807075781391858178889652208164348344825993266043367660176999612831860788386150279465955131156552036093988180612138558600301435694527224206344631797460594682573103790084024432438465657245014402821885252470935190620929023136493273497565513958720559654228749774011413346962715422845862377387538230483865688976461927383814900140767310446640259899490222221765904339901886018566526485061799702356193897017860040811889729918311021171229845901641921068884387121855646124960798722908519296819372388642614839657382291123125024186649353143970137428531926649875337218940694281434118520158014123344828015051399694290153483077644569099073152433278288269864602789864321139083506217095002597389863554277196742822248757586765752344220207573630569498825087968928162753848863396909959826280956121450994871701244516461260379029309120889086942028510640182154399457156805941872748998094254742173582401063677404595741785160829230135358081840096996372524230560855903700624271243416909004153690105933983835777939410970027753472000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 (at least) increment operation will take quite a while

Name: Anonymous 2011-04-06 11:30

>>55
(make-string (fact 1000) #\+)

Name: Anonymous 2011-04-06 11:40

>>56

I don't see where I made an error.

Name: Leonidas 2011-04-06 11:42

lol, retards

4 lines in java

import java.math.BigInteger;
public class Factorial {
    public static void main(String[] args) {  
        //-- BigInteger solution.
        BigInteger n = BigInteger.ONE;
        for (int i=1; i<=1000; i++) {
            n = n.multiply(BigInteger.valueOf(i));
        }
        System.out.println(n);   
    }
}

Name: Anonymous 2011-04-06 11:43

>>60

3 lines actually

BigInteger n = BigInteger.ONE;
for (int i=1; i<=1000; i++) {
n = n.multiply(BigInteger.valueOf(i));

Name: Anonymous 2011-04-06 11:43

Name: Anonymous 2011-04-06 12:21

>>60
lol retard, one line in <insert name of one of bazillions languages>

Name: Anonymous 2011-04-06 15:32

print reduce(lambda a, b: a * b, range(1, 1000))

putStrLn $ show $ product [1..1000]

(1..1000).reduce(:*)

lists:foldl(fun(A, B) -> A * B end, 1, lists:seq(1, 1000))

Name: Anonymous 2011-04-06 16:15


factorialere sic
  da meo numerum parprimum.
  unum meo resulto da.
  si numerum tum nullum aequalitam fac unum redde.
  dum numerum fac sic
   resulto damentum numerum tum numerum unum deme multiplica.
   numerum damentum numerum unum deme.
  cis
  numerum redde.
cis

Name: Anonymous 2011-04-06 21:25

>>39
>>40
ok

Name: Anonymous 2011-04-07 12:00

>>64
Python, Haskell, Perl and what is the last one?

Name: Anonymous 2011-04-07 12:16

>>67
Looks like Erlang.

Name: Anonymous 2011-04-07 13:41

>>64
.reduce(:*)
(:*)
:*

Name: Anonymous 2011-04-07 13:48

>>65
Is that some Perl?

Name: Anonymous 2011-04-07 14:12

>>70
It's valid Perl code, yes.

Name: Anonymous 2011-04-07 18:34

>>69
69
(* ) ( *)


inb4lrn2quote Shut the fuck up. It's two [b][i]SEPARATE[i][/b] quotes!

Name: Anonymous 2011-04-07 18:37

>>72
lrn2bbcode

Name: >>72 2011-04-07 23:20

>>73
Oh shit, I posted it and I only saw it now.

It's such a shame. Let me fix it:
It's two SEPARATE quotes!

Name: Anonymous 2011-08-31 15:56

>>13

(define small-odd-swing
  (vector 1 1 1 3 3 15 5 35 35 315 63 693 231 3003 429 6435 6435 109395 12155 230945 46189 969969 88179 2028117 676039 16900975 1300075 35102025 5014575 145422675 9694845 300540195 300540195))


WTF is this? This is what I found:
``Odd part of the swinging factorial''
http://oeis.org/A163590
http://www.luschny.de/math/swing/SwingingFactorial.html

How do you use this sequence to speed up the computation of factorial 1000? Care to explain?

Name: n3n7i 2011-09-01 1:16

Done in 3 sec using Thousandfold + Binary Alg =)

285 places on Base 10^9....

Name: Anonymous 2011-09-01 1:33

>>1
I can do it in one line of C, assuming I get to include some sort of bignum math library.  I don't see why I shouldn't, since Haskell does.

Name: Anonymous 2011-09-01 1:40

>>77
Ah, wait, I don't even need the bignum library:

#include <stdlib.h>
int main(int argc, char **argv) { return system("start http://www.wolframalpha.com/input/?i=1000!"); }

Ok, two lines of code but the #include isn't usually considered a line of code.

Name: Anonymous 2011-09-01 2:02

>>78
Or you could call Haskell from C, which would be much faster than requesting wolframalpha over the network.

Name: n3n7i 2011-09-01 2:16

!1500 in 5 sec =)

It looks like this
48,119977967,797748601,669900935,813797818,348080406,726138081,308559411,630575189,1095591,292230585,206733851,868464009,619343585,194052091,124618166,270271481,881393331,431627962,810299844,149333789,44689395,510487167,879769325,303699470,467829234,399263326,545652860,748605075,746366928,323606645,492277541,120083438,86727369,377887676,211405,318480244,354207419,604864176,969950581,435222198,851194568,984095705,945549589,54568321,792338919,149442985,919957734,792959402,499096845,643020401,869381175,603964424,333222114,125974374,817804242,633309769,804293952,870034619,354125014,210045647,664063240,162007560,108665290,568646128,342557147,350985358,724154623,253371867,470765120,422073867,963935775,258692109,753041762,94343569,50497470,353531764,481503174,750911858,230906998,361066084,787758316,110585736,13365377,431860738,572261325,738233656,835271947,352695180,865573043,834027955,539012765,489372645,42504406,597752357,481931532,872356635,411224578,334040522,294746402,829585458,478708778,346379431,862368824,819009177,91444034,885941394,319343910,223168655,869761799,669075059,527608502,465593181,398566214,786801211,651657222,4123456,498258513,120359126,22843038,535083709,796101565,934859483,203933443,308601475,813108363,74118562,404412420,191947127,585482919,172173045,961122122,701434297,870691932,154082986,945954748,251105782,181586397,275820342,101470457,300633590,139512919,549474113,721711616,912519714,191760699,935509810,254849967,87635936,181176363,954224186,31346682,928878492,872249485,456690138,831610135,377916327,940503701,400290125,509132140,782614640,495733518,48670983,360134097,860364762,638658894,873174499,870133559,364805443,430831459,505987809,215393353,387232078,177562975,21460595,422358573,128085417,162336030,235138652,735438053,34531962,620811566,19896879,275257163,988352090,874930346,115518331,202927263,708446729,394381879,888839549,731876978,682249320,628599631,628662375,508826209,854754631,984276392,670919216,923002770,77734756,77549035,942976209,159416211,581439461,484509549,370357486,770276807,687544580,164314647,595031368,948490282,897173328,13518435,758700056,425922638,411889496,527975846,52717958,44813737,86806600,171993703,579485864,29383208,714528950,303253881,360812631,162134750,100307772,634337467,12820470,715650810,714689905,121432259,528505483,53930402,217400686,61612471,659630192,434864094,539828085,677465383,26128353,771071152,304197549,798870706,139893609,140045659,756285435,787771636,258253666,592102151,236142132,724425850,991205720,20493660,580896600,891888594,659612927,724357866,265934517,615841298,789154462,249169688,860092640,284756382,431746120,357767933,119589280,468687348,61788072,986362788,582227019,465263474,828590646,48451070,702923434,422714349,595857654,843699542,321849363,652767771,978314681,13589442,955219879,702008068,934096624,650625769,705233333,462826013,860098698,155180331,145365652,453482955,497979915,586438474,687345677,874451117,702250441,711504844,638414485,210092261,397271970,571029038,581873069,951161330,495772310,508760528,249706514,238384269,808639507,80418298,318311361,373628512,41716415,196868334,254119137,139589149,597210032,153545941,114666530,498906529,240798164,804007394,775927836,45668573,993316428,972539932,745757171,947402454,257142633,700815922,407278403,640595355,142075599,446056337,986717212,316223257,763412164,180899532,722039383,244462511,410346646,148863397,237096276,822656157,561194665,545757017,429842404,840309758,925618650,507921043,7241637,877939825,811059339,138925526,124514467,627126548,126795078,784022672,860886251,974581362,141782786,407402896,309678008,909663263,987018538,107050886,193489012,497405005,820727271,232733728,141775132,722013860,591169620,692789290,456794698,409808557,447756701,311883266,10859016,27592252,397754508,251628808,293537776,536569608,111330584,797160694,847898923,196743970,244451842,702266403,326317319,92117151,143971679,500042590,269255093,130215984,418097418,435474300,467281949,798227102,529873732,749027992,79700287,275900856,241172902,880909546,551703263,202853584,498085358,955307673,717177961,902081098,618729046,348849060,249600000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

10 ^ 9 * 457

Name: Anonymous 2011-09-01 2:43


go fuck an autistic nigger, you fucking assburgers fagstorm shitbreath pencildick nigfucker

Name: n3n7i 2011-09-01 3:16

!2500[/code]16288,884241692,635468966,810574743,966336539,994283436,659333376,117059851,739595300,666601568,118117109,111430182,218994996,706377540,737964295,726648036,84914477,39
8269956,576650394,995303908,153606931,358938562,424868716,863336511,787772831,963234651,490597845,804707452,80712773,761945183,179002366,243765637,991536689,969242581,
709947395,573553799,155162061,20587956,162836453,609056109,182552093,352343844,29882417,375246821,954281460,20336896,525591606,956233891,343329496,954631026,393022945,
474865068,966259267,963805071,707264234,749398946,807274223,651874046,23994635,224545104,61309775,665397330,572064502,645799793,490535692,439961861,758186037,617483580
,487420516,854225746,700866725,272078424,896992597,788322485,750313103,767538280,635190313,55438652,113070059,895360069,459016503,698021402,127430434,703720577,4546036
84,221486207,712971570,279183098,247144580,669751192,292412687,570776382,442783145,813125272,512987140,13465430,577373695,416037438,604330731,495427723,748498601,31677
7072,913720020,200624759,285687594,697103942,902831458,433117148,104802139,150255844,954156372,702572242,931979348,640772104,241935322,544694355,717741028,42721831,573
93383,946811950,229862119,18492668,601533950,515675995,793861869,111189410,513752442,848879659,1774939,446410165,714053104,744903131,715021128,531205114,521790600,4483
2229,285647606,408017904,177251780,563861670,452217895,698401839,16268343,830469429,772772782,341220769,473426587,820287290,19473077,524695825,215527904,355576391,3056
00088,839325393,721013677,844373796,989572057,534519771,31549187,963257721,208029673,279152430,652933276,800258223,453219383,978743812,269682334,913717476,68767081,112
170724,712287720,561807845,229060596,372853438,939340670,348358259,624827210,411996569,765719571,305348561,907445521,649287971,976375847,487178355,765492815,778069121,
838364685,540983459,992106337,314470299,659462768,807774194,455026719,275830902,631301620,632068053,5745274,643641270,818310893,189040468,508343150,208376066,332465734
,970601526,332798266,648668957,684928388,346914251,393674102,236838190,309415765,24962992,701286434,254040733,64624752,399588405,701518471,706282680,92033896,216655874
,206291783,633993514,147758055,661610275,976159918,807613941,637566649,34779587,69377199,455553747,637235892,554444579,113470055,333978002,998933446,236448649,95633864
3,549877097,69790252,117694271,543914179,639916424,71991406,456604783,333397965,866797905,100968905,477558448,660543042,454554471,492045598,502849277,515838640,5002083
65,860739763,710206685,971849678,108935761,798782539,66278141,381636294,637082189,768125799,193702797,967538238,466562473,387279176,788278704,807481230,413644276,13972
0229,104456308,83258037,763826781,395687638,241302508,20291782,679358425,712165041,212352088,250542961,656610307,562083717,426864028,254048045,585013278,396707312,9880
98509,307199244,525251413,18638107,871271406,375801619,527964709,310126699,327425652,342396160,313371140,810226949,214136412,603864243,886523013,717112551,532688276,16
4952934,427157810,894957954,46837445,796764595,217297020,162001470,343757782,370085850,953552320,637100882,919579912,163108370,28314403,969241003,234290634,568270458,9
55949171,264334907,57977769,908075381,921113966,351587586,648467738,374135641,552139894,953507856,890412402,614641785,184184650,269635082,32520382,461666556,52083240,7
49659841,927331974,627710176,727263009,232886075,400144727,578901134,34342119,214962884,370001625,512726452,523206152,157166541,752489388,503280463,130706903,614053713
,733296237,361667312,991010932,983656540,560377330,832262770,42696095,731040694,487906848,645462190,989961711,109989113,241974798,68964703,59871195,609328565,827196434
,230198178,800412242,371942746,686047154,961984072,73558094,313894903,724884222,66777831,669419732,898160360,633747237,482986968,369023008,889690448,245258289,10570687
6,230750084,254201797,244121746,320131347,525589214,486094781,766265733,538907918,16852228,868499907,315181338,394080723,321126032,440189828,823699970,328255861,187143
922,82019147,768883662,612191302,509135461,511051477,630808296,519282900,741066316,50077242,544314881,58045728,870693282,326830433,19004661,600521723,836651817,3815298
98,440636383,917095475,899004094,206317468,376377314,153856018,840069377,218558903,334939371,343395777,264426365,318130887,683599836,88345497,158322556,553595094,84089
4654,614406383,376396868,199531042,942079405,403474627,428650274,595771829,568255995,466465003,325664472,293654101,201924430,539079190,443194487,46380416,281749159,263
00696,294947812,447714612,418298771,332692848,211154125,929312681,287195951,419960699,391722211,424311898,584816200,565373258,799897110,855302098,610980845,978364362,6
85231061,369005215,230788471,798866541,648729889,538439509,890111560,301062943,923923769,988997147,648363950,708508382,34563798,637202146,673551309,938897540,440786998
,3118907,883241416,258343188,784000679,367284896,11745823,289734561,911522255,979545433,492376668,285434347,783001266,108600121,473498779,217963921,384546755,156766188
,951735866,744108093,964636023,471349527,19498920,540070752,394649104,708510770,999131507,315610483,632330982,876174119,389012968,417760250,231722884,408641474,3403748
93,362833795,392300949,100935853,949419952,854923937,872507275,773843355,108735204,114864752,466565493,366395162,830913421,138498633,186453324,268762572,668445390,7709
03011,717202242,312950408,723851830,364004678,106656009,78222984,968635868,416766693,788940980,240045058,68275614,302839043,567118028,698385054,274108921,811298084,233
976240,6277809,181325997,330000786,683674194,376654268,377368369,949823431,206244095,885960702,59149846,318232687,179678572,748082487,793549844,548187548,311400556,647
44050,666472476,457947299,489568330,636742840,865513804,654776149,494225932,236964194,164784786,218640251,626514525,549920894,810545056,499250214,652147224,638246034,8
92251401,29945773,476251196,919612592,752826016,419187902,895630887,737745713,281219681,141023586,882321633,118519558,748181198,803719862,314967759,867112077,291645583
,600510531,17148754,676649505,951293767,894337326,791942862,414631993,126449392,270145239,108425380,56269282,654566300,820253116,701666036,949374826,952156733,28626270
0,190206665,725355635,411559887,439781283,350874285,109852181,238143636,938256407,98028863,909426094,536431398,247852543,854757537,942646791,855344906,17659039,3849051
22,375234004,320416026,882823286,655632286,53156546,748028668,750196973,803337027,786891236,116711910,780819707,846081218,679760982,625290715,984522150,204916425,23259
1826,590887410,401320568,45430558,979943145,617193692,59705465,421939829,497586908,594951642,657711985,208269462,425640322,372314303,330475772,671495014,49400654,15561
9566,942191085,558759378,416790160,458835621,823599743,742665152,596726797,511419955,382867531,134959437,2011587,472231152,746047820,309830039,699792147,174883667,8557
60287,780241438,38062954,704157981,72533480,950728570,115662921,849376586,317866043,9133972,729549191,452640224,225320222,817060812,601144385,749818368,781373067,88882
7129,923654130,858902252,804622762,751192618,314790547,633755929,57344102,888830740,499275949,997990026,813425216,747458578,654838647,236496508,876074530,642629714,199
563056,483975900,965902520,59913821,418901761,372054615,449749487,163282905,699188377,895083782,877246773,269374715,942460000,414707728,522199826,307191493,572953655,7
49106244,370767768,17669677,808468909,623091993,519298870,943235516,530358122,980923396,832082235,382703392,292864000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
[/code]

Name: Anonymous 2011-09-01 3:24

Name: Anonymous 2011-09-01 9:03

Hey C fags when you include a header the amount of lines in your program actually increases, if it didn't you could just write everything under one big macro include a header and do EVERYTHING as a one liner, you have to explicitly use extern or your code is invalid and the amount of lines used compiler/system/architecture dependent.

Name: Anonymous 2011-09-01 9:38

@Anonymous
No, those are standard library functions. Just like "alert" in javascript. The calculations are not done by iostream.

Name: Anonymous 2011-09-01 9:39

@Anonymous
No, those are standard library functions. Just like "alert" in javascript. The calculations are not done by iostream.

Name: Anonymous 2011-09-01 9:40

Sorry for double post. Seems like double click is double post on my browser...

Name: Anonymous 2011-09-01 10:03

((λ (n) ((((λ (f) ((λ (fs) (λ (n) (λ (a) (if (= n 0) a ((fs (- n 1)) (* a n)))))) (λ (a) ((f f) a)))) (λ (f) ((λ (fs) (λ (n) (λ (a) (if (= n 0) a ((fs (- n 1)) (* a n)))))) (λ (a) ((f f) a)))))
 n) 1)) 1000)

Name: Anonymous 2011-09-01 10:16

>>88
Even lambda calculus is shorter and more readable than C.

Language for real man my anus.

Name: Anonymous 2011-09-01 11:38

!x:1e3

Factorial of extended precision value of 103. J, motherfuckers.

Name: Anonymous 2012-07-15 23:49

>>46
fuck you and die you little queerfag, this is /prob/, we are here! that is all!

Name: Anonymous 2012-07-16 0:10

>>88
Please teach me your magic, wizard.

Name: Anonymous 2012-07-16 0:18

I've tried and tried to understand lambda calculus but my dumb ass struggles to retain the information and I just don't get it. Maybe the context-free grammar thing is too confusing for me.

So, could someone please share a good tutorial for absolute fagstorms?

Name: Anonymous 2012-07-16 0:23

>>93
Read SICP.

Name: Anonymous 2012-07-16 0:37

>>93
It's a lot simpler than you think.

Name: Anonymous 2012-07-16 0:37

A fack of four is twenty four.

Name: Anonymous 2012-07-16 1:01

(define (hax anus) (cond ((= anus 1) 1) (else (* anus (hax (- anus 1))))))
(hax 1000)

http://imgur.com/iaxdy

>>82
http://imgur.com/mx4T2

Name: Anonymous 2012-07-16 2:02

multithreaded haskell factorial for the win: 2 million factorial in less than 19 seconds.

$ ./factorial 20000000 +RTS -s
37768210576
(~11MB of digits snipped)0000000000
   1,648,364,640 bytes allocated in the heap
     325,424,052 bytes copied during GC
      18,401,832 bytes maximum residency (29 sample(s))
       1,815,432 bytes maximum slop
             130 MB total memory in use (13 MB lost due to fragmentation)

                                    Tot time (elapsed)  Avg pause  Max pause
  Gen  0      1411 colls,  1410 par   12.93s    2.91s     0.0021s    0.0557s
  Gen  1        29 colls,    29 par    3.18s    0.54s     0.0185s    0.1733s

  Parallel GC work balance: 1.37 (81339519 / 59252792, ideal 8)

                        MUT time (elapsed)       GC time  (elapsed)
  Task  0 (worker) :    0.00s    ( 18.71s)       0.03s    (  0.22s)
  Task  1 (worker) :    1.65s    ( 15.39s)       2.62s    (  3.54s)
  Task  2 (bound)  :   14.96s    ( 15.62s)       2.79s    (  3.31s)
  Task  3 (worker) :    0.00s    (  0.00s)       0.00s    (  0.00s)
  Task  4 (worker) :    0.02s    ( 13.83s)       2.17s    (  5.09s)
  Task  5 (worker) :    0.02s    ( 13.84s)       2.87s    (  5.09s)
  Task  6 (worker) :    0.02s    ( 13.81s)       3.57s    (  5.12s)
  Task  7 (worker) :    0.06s    ( 13.82s)       3.71s    (  5.11s)
  Task  8 (worker) :    0.03s    ( 13.81s)       3.49s    (  5.12s)
  Task  9 (worker) :    0.05s    ( 13.81s)       3.53s    (  5.12s)

  SPARKS: 902 (788 converted, 0 overflowed, 0 dud, 0 GC'd, 114 fizzled)

  INIT    time    0.00s  (  0.00s elapsed)
  MUT     time   25.47s  ( 15.49s elapsed)
  GC      time   16.11s  (  3.44s elapsed)
  EXIT    time    0.00s  (  0.00s elapsed)
  Total   time   41.59s  ( 18.93s elapsed)

  Alloc rate    64,705,280 bytes per MUT second

  Productivity  61.3% of total user, 134.6% of total elapsed

gc_alloc_block_sync: 25914
whitehole_spin: 0
gen[0].sync: 0
gen[1].sync: 286

Name: Anonymous 2012-07-16 2:03

step

Name: Anonymous 2012-07-16 2:09

20000000
oops. copied the wrong first line, couldn't just copy the whole thing on account of my scrollback buffer being much smaller than 11MB.

Name: Anonymous 2012-07-16 3:08

haskell is shit

Name: =*=F=R=O=Z=E=N==V=O=I=D=*= !frozEn/KIg 2012-07-16 5:16

>>84
did you called for me?
_______
delenda terrum bullshit orbit est.

Name: Anonymous 2012-07-16 10:52

>>94
Ah, I haven't read it yet. I guess I should.

Name: Anonymous 2012-07-16 13:02

Total   time   41.59s  ( 18.93s elapsed)
What manner of witchcraft is this?

Name: Anonymous 2012-07-16 15:41

memset(y, '\0', LENGTH);
oh lawd imagine how slow this is

Name: Anonymous 2012-07-16 23:59

In APL:
×/⍳1000
In NARS2000, it's even shorter:
!1000x

Name: Anonymous 2012-07-17 0:01

ITT slow as fuck factorials that take several seconds to do what should only take a couple milliseconds at most.

Name: Anonymous 2012-07-17 2:19

>>107
Mine only took a couple milliseconds, don't know what you're talking about.

Name: Anonymous 2012-07-17 6:43

>>108
You are in the minority in this thread.

Name: Anonymous 2012-07-17 7:07

>>105
The entire thread is full of people described by Yossi here: http://yosefk.com/c++fqa/ctors.html#fqa-10.9 -- the people who think that they care about performance, but all they really care about is stroking their egos by participating in discussions, in this case on an anonymous textboard for added patheticalness.

Name: Anonymous 2012-07-17 8:47

>>8
332 bytes

#include<stdio.h>
int x[3][9999]={{1}},i=0,j,k,a,b;main(){while(i++^1001){for(x[2][0]++,j=0;x[2][j]>9;j++)x[2][j]%=10,x[2][++j]++;a=i&1,b=a^1;for(j=0;j<2568;j++)for(k=0;k<2568;k++)x[a][j+k]=x[b][j]*x[2][k]+(j?x[a][j+k]:0);for(j=0;j<2568;)x[a][j+1]+=x[a][j]/10,x[a][j++]%=10;}for(j=2567;j>=0;j--)printf("%d%s",x[i&1][j],j?"":"\n");}


$ gcc fact.c -O4
$ time ./a.out
real    0m7.641s
user    0m7.612s
sys    0m0.004s

Name: Anonymous 2012-07-17 10:23

ITT: Single threaded, no SSE

Nice failed priorities

Now go back to jerking off to hentai

Name: Anonymous 2012-07-17 10:52

>>112
>>13,15 is trivially parallelisable.

Name: Anonymous 2012-07-17 15:11

>>112
fuck you and die, faggot

Name: Anonymous 2012-07-17 15:45

>>112
jerking off to hentai
I never got the appeal of hentai. Ecchi, on the other hand, makes me cum massive buckets.
Maybe I am too innocent for actual hentai. ;_;

Name: Anonymous 2012-07-17 15:49

>>113
What is the sorcery with the "odd part of the swinging factorial"?

Name: Anonymous 2012-07-17 19:28

>>116
Premature "optimization" that, in Haskell at least, actually makes it a bit slower.

>>113
It still takes over a second to do what should take less than 10 milliseconds.

Name: Anonymous 2012-07-17 21:32

>>115
I understand. Hentai is nice when it's vanilla, though.

The good thing of ecchi is that it lets your imagination do whatever the hell it wants and I think it's hotter that way. While you're restricted to PLEASE INSERT YOUR OCHINCHIN INSIDE MY PUSSY KYAAAAAAAAAAA with hentai.

Name: Not >>115 2012-07-17 21:45

>>118
Yup.

Name: Anonymous 2012-07-18 14:12

>>117
be patient, geez
i bet you get your ANUS in a knot every time you have to wait in the line for a concert

Name: Anonymous 2012-07-18 14:26

>>120
concert
get a load of this pleb

Name: Anonymous 2012-07-18 16:37

>>121
get a load of this pleb
Back to the imageboards, ``please"!

Name: Anonymous 2012-07-18 17:52

>>120
Being patient won't make your horribly inefficient code more efficient.

Name: Anonymous 2012-07-18 18:25

>>120
As >>123 pointed out, the problem isn't that it's slow. The problem is that it wastes processor time that could be used for other tasks, or energy that could be saved by not running the processor (or running it at a slower clock speed while idle).

Name: Anonymous 2012-07-18 23:59

>>123
>>124
then work a bit more and earn those extra pennies in less than 15 seconds
you're not going to die for working 5 seconds more

and stop using x86

Name: Anonymous 2012-07-19 0:12

>>125
The Lemote 8133 is not yet out, I will keep using x86.

Name: Anonymous 2012-07-19 1:30

>>125
I bet you're one of those assholes who say that 5 miles per gallon ought to be good enough for anybody. Wasting electricity means wasting fossil fuels, and no amount of work will appreciably change the amount of fossil fuels available on Earth.

Name: Anonymous 2012-07-19 3:14

>>127
My entire household is powered by wind and sun power. Checkmate, faggot.

Name: Anonymous 2012-07-19 6:55

>>128
So you live in your car?

Name: Anonymous 2012-07-19 7:01

wind and sun power
03:14
You are obviously lying. Checkmate, faggot.

Name: Anonymous 2012-07-19 7:09

expert programmers use as many fossil fuels as they please because everyone knows lemote is for chinamen

Name: Anonymous 2012-07-19 9:55

expert programmers use ac cords on their laptops because everyone knows batteries is for faggots

Name: Anonymous 2012-07-19 11:34

>>132
Real programmers don't use laptops.

Name: Anonymous 2012-07-19 12:20

>>130
Energy can't be stored in batteries, nor is there any wind at night.
ISHYGDDT

Name: Anonymous 2012-07-19 16:12

>>134
You forgot
Hour of day being universal across the surface of the Earth.

Name: Anonymous 2012-07-19 19:17

>>134
Batteries are not "wind and sun power". Also, no sun = no wind.

>>135
Sorry, >>134 already admitted to it being night at his location.
Good job calling my bluff after the fact.

Name: Anonymous 2012-07-19 23:32

>>136
Beaches?

Name: Anonymous 2012-07-19 23:43

Oh, penii.

Name: Anonymous 2012-07-20 13:57

Who Gives a fuck about faktorial i want GAMMA FUNCKTION IMPLENMENTANTION RITE NAO!!!!!!!!!!!!!
IVE BEEN TRYING FOR MONTSH TO FIGURE OUT HOW GAMMA FUNCTIONdsagdBAUIDHBADSikhjui!? AND MY NEURAL NETS DONT CONVERGE FUCK THIS SHIT

Name: 139 2012-07-20 13:57

>>139
(or Logarithm of gamma)

Name: Anonymous 2012-07-20 14:09

OH WAIT MY COMPILER HA S BULILT IN LIBRARY TO DO LOG_GAMMA BUT I HAVE no CLUE HOW the HELL IT DOES IT SO EXPLAIN ME THE STEPS IN GETTING THE GAMMA FUNCTION OR MAYBE POSSIBLEY EVEN AN ASM CODE SNIPPET SOR SOMETHING INSANELY CRazy LIKE TGAt LOL!!
IF YOU DONT GOING TO DO PUT CODE HERE I WILL ANALYZE THE CODE MYSELF!!!!!!!!!!!!!!!!!!!!!!! BUT THATS HRARD TO DO!!!!!!!! THEREFORE U MUST POST HERE CODE OR I WIL BE BUTTTTTTT ANGREY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~~~

Name: Anonymous 2012-07-20 17:59

product([], 1).
product([H|T], X) :- product(T, Y), X is H * Y.

factorial(N, R) :- numlist(2, N, Ns), product(Ns, R).

Name: Anonymous 2012-07-20 22:55

>>142
This is unnecessarily memory inefficient, not tail-recursive, only works one way and it also does not conform to ISO-Prolog.

successor(X, Y) :-
        number(Y) -> X is dec(Y); number(X) -> Y is inc(X);
        throw(error(instantiation_error, successor/2)).

nonnegative(0).
nonnegative(N) :-
        number(N) -> N > 0;
        nonnegative(M), N is M + 1.

factorial(0, R, R) :- !.
factorial(N, P, R) :-
        successor(M, N), A is N * R, factorial(M, P, A).
factorial(N, R) :-
        nonnegative(N), factorial(N, R, 1).


Whether the query

?- factorial(100, N).

actually yields the correct number also depends on the implementations limitations when it comes to integers.

Name: Anonymous 2012-07-21 1:22

>>143
WTF does that even do? I know it squares a number, but how?

Name: Anonymous 2012-07-21 1:34

>>144
It does in fact not square any number unless you are referring to the number 1, but that is indeed the only number it will square.

As for how it is done, that is just a silly implementation detail.

Name: Anonymous 2012-07-21 1:38

>>145
is that an easter egg

Name: Anonymous 2012-07-21 1:40

>>146
Are you referring to the squaring of the number 1? Then no, it is a consequence of both 0! and 1! being 1.

Name: Anonymous 2012-07-21 1:41

2976579765 in decimal hurr

Name: Anonymous 2012-07-21 2:21

>>143
If you're going to bitch about inefficiency, you really should do it right.

product([], 1).
product([H|T], X) :- product(T, Y), X is H * Y.

sieve(N, [2|PS]) :-       % PS is list of odd primes up to N
    retractall(mult(_)),
    sieve_O(3,N,PS).

sieve_O(I,N,PS) :-        % sieve odds from I up to N to get PS
    I =< N, !, I1 is I+2,
    (   mult(I) -> sieve_O(I1,N,PS)
    ;   (   I =< N / I ->
            ISq is I*I, DI  is 2*I, add_mults(DI,ISq,N)
        ;   true ),
        PS = [I|T],
        sieve_O(I1,N,T)
    ).
sieve_O(I,N,[]) :- I > N.

add_mults(DI,I,N) :-
    I =< N, !,
    ( mult(I) -> true ; assert(mult(I)) ),
    I1 is I+DI,
    add_mults(DI,I1,N).
add_mults(_,I,N) :- I > N.

prime_power_of_s(_, 0, A, S) :- S is A.
prime_power_of_s(P, N, A, S) :- Q is div(N, P), R is mod(N, P), B is A + R, prime_power_of_s(P, Q, B, S).

prime_power_of(N, P, R) :- prime_power_of_s(P, N, 0, S), R is div(N - S, P - 1).

factorized_factorial(N, Ps, Rs) :- sieve(N, Ps), maplist(prime_power_of(N), Ps, Rs).

exponentiate_factors([], [], []).
exponentiate_factors([P|Ps], [R|Rs], [N|Ns]) :- N is P ** R, exponentiate_factors(Ps, Rs, Ns).

factorial(N, R) :- factorized_factorial(N, Ps, Rs), exponentiate_factors(Ps, Rs, Ns), product(Ns, R).

Name: Anonymous 2012-07-21 2:25

>>149
This is orders of magnitude slower than the tail recursive version it also takes up lots more memory, it also reeks of premature optimization.

Name: Anonymous 2012-07-21 3:00

>>149
the fugliness of your code is only matched by its author's.

Name: Anonymous 2012-07-21 3:02

>>150
Your shitty (GNU?) implementation is showing. >>149 is tail recursive, much faster than >>143, and uses much less memory. Also, on a decent implementation, >>142 is only slower than >>143 by a small constant factor, and uses a about the same amount of memory.

Name: Anonymous 2012-07-21 3:05

>>152
And yet it doesn't even manage to answer the simple query

?- factorial(X, 1).

without borking.

Name: Anonymous 2012-07-21 3:12

>>153
Why would you even want that?

Name: Anonymous 2012-07-21 3:13

fack dabz

Name: Anonymous 2012-07-21 11:01

>>154
Because it's fucking Prolog and by simply describing the problem it should be able to relate either way, you know, like most Prolog rules do.

Name: Anonymous 2012-07-21 14:51

>>156
?- A + 3 is 5.
false.

Name: Anonymous 2012-07-21 17:12

>>157
Yes evaluated arithmetic doesn't work both ways, so you have to actually think.

Name: Anonymous 2012-07-21 18:35

>>158
I'm pretty sure that was >>157's point, in response to >>156's irrational belief that Prolog should make thinking on his part unnecessary.

Name: Anonymous 2012-07-21 19:33

>>159
Nope that's not what I said. I said that you should design rules that work both ways, since it's Prolog and end users kind of expect usability.

There is a golden middle road here, where ISO-Prolog implementations can easily figure out what you're trying to do while also making the solution efficient, in any case the most stable and usable implementation never looks like >>142 or >>149.

Name: Anonymous 2012-07-21 20:56

Prolog was made in France, and France is fucking shit.

Go fuck an autistic ``le parfum d' snail".

Name: Anonymous 2012-07-21 23:17

I said that you should design rules that work both ways, since it's Prolog and end users kind of expect usability.
Why isn't is/2 designed that way?

Name: Anonymous 2012-07-21 23:32

>>162
I'd gather that backtracking through the full numeric tower would be too much of an academic masturbation even for Prolog. We have set theory for that.

Name: Anonymous 2012-07-21 23:59

too much of an academic masturbation even for Prolog
I seriously doubt such a thing is possible.

Name: Anonymous 2012-07-22 0:26

>>162
Arithmetic in Prolog is basically just a hack, you can't always invert complex mathematical operations (let alone do it efficiently) so you would end up with what >>163 says unless you weren't extremely careful about it. Prolog was designed to work on real computers after all.

This doesn't mean that you should design stupid and unusable shit with it though.

Name: Anonymous 2012-07-22 2:43

Fuck it, did it with a bignum library in Go while high last night, come at me.


package main

import (
    "math/big"
    "fmt"
)

func main() {
    sum := big.NewInt(1)
    for i := int64(1000); i > 1; i-- {
        sum.Mul(sum, big.NewInt(i))
    }
    fmt.Println(sum)
}

Name: Anonymous 2012-07-22 3:33

Would anyone care to show me how to use numeric transform to do multiplication in O(n log n)?

Name: Anonymous 2012-07-22 3:34

fuck I meant number-theoretic

Name: PUDDI 2012-07-22 4:16

>>46
puddi -c 'print reduce(lambda x,y:x*y,xrange(1,1000))'

Name: PUDDI 2012-07-22 4:16

>>46 fuck
puddi -c 'print reduce(lambda x,y:x*y,xrange(1,1001))'

Name: Anonymous 2012-07-22 6:05

>>166
Holy fuck, with a bignum library? Are you crazy? That's hardcore.

Name: Anonymous 2012-08-03 19:02


in ruby

(0..1000).reduce(:*)

ermagawsh that was difficult
will someone shut these faggots up please

Name: Anonymous 2012-08-03 19:24

>>172
How many centuries does that take to run?

Name: Anonymous 2012-08-03 19:35

>>173
I'd like to tell you, but the estimator I wrote is still running.

Name: Anonymous 2012-08-03 20:20

>>172
wrong output

Name: Anonymous 2012-08-03 20:29

>>175
ruby programmers users can't into programming.

Name: Anonymous 2012-08-03 21:36

>>172
0 * 1 * 2 * ... * 1000 = ?

Name: Anonymous 2012-08-03 21:53

[*]-<<+^<<^1000
VALID PERL 6 CODE

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