Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ?!
- ,>++++++[<-------->-]<[->+>+<<]>>->>+<<<[>[<[->[-<<+>>>+<]>[-<+>]<<]<[->+<]>>-]<.>>>-]>>>[.-]
- ,
- >++++++ Put 6 in next cell
- [<-------->-] Subtract 8 six times to subtract 48
- <
- [->+>+<<] Move (0) to (1) and (2)
- >>- Decrement one from (2) as we want to multiply n * n minus 1
- >>+ Store 1 in (4) to allow distinguishing 0 separately
- <<< Go to (1)
- [ A makeshift if($_ != 0)
- >[ While (2)
- <[ While(1)
- - Subtract one from (1) for multiplication by repeated addition
- >[-<<+>>>+<] Add (2) to (0) and (3)
- >[-<+>] Move data from (3) to (2)
- <<
- ]
- <[->+<] Copy (0) to (1) for next round of multiplication
- >>- Decrement (2) to go to n minus 2 and so on
- ]
- <.>>>- Print output from (1) and make (4) = 0 to stop the if
- ]
- >>>[.-] If we're at (4) (and it is nonzero) we have a 0 as input; so print 1 and stop;
- [->+>+<<]>>->>+<<<[>[<[->[-<<+>>>+<]>[-<+>]<<]<[->+<]>>-]<.>>>-]>>>[.-]
- n->product[1..n]
- fac n = product [1..n]
- fac n = foldr (*) 1 [1..n]
- #include <iostream>
- template <int N>
- struct Factorial
- {
- enum { value = N * Factorial<N - 1>::value };
- };
- template <>
- struct Factorial<0>
- {
- enum { value = 1 };
- };
- int main()
- {
- std::cout << "4!=" << Factorial<4>::value << std::endl;
- }
- #AT&T syntax
- mov %eax, %ebx
- again:
- dec %ebx
- .byte 0x74, 4 #jz (short) done
- mul %ebx
- .byte 0xEB, -7 #jmp (short) again
- done:
- set r=1
- for /l %%i in (1,1,%1) do call set/a r=%%r%%*%%i
- echo %r%
- // uint32_t factorial(uint32_t n, uint32_t *result, uint32_t length);
- //
- // stores n! in the buffer result as a little-endian bignum. length is
- // size of the buffer in (32-bit) words. It is the caller's responsibility
- // to allocate and free the result buffer. If the buffer is not large
- // enough to contain n!, 0 is returned. On successful exit, the return
- // value is the number of (32-bit) words of the buffer that were used to
- // store the result.
- _factorial:
- push {r4-r7}
- tst r2, r2
- beq Lerror
- movs r3, #1
- str r3, [r1]
- tst r0, r0
- beq Ldone
- Lloop:
- eors r6, r6
- movs r7, r3
- Lmultiply:
- movs r5, r6
- eors r6, r6
- ldr r4, [r1]
- umlal r5, r6, r0, r4
- str r5, [r1], #4
- subs r7, $1
- bne Lmultiply
- tst r6, r6
- beq LnoOverflow
- adds r3, $1
- cmp r3, r2
- bhi Lerror
- str r6, [r1], #4
- LnoOverflow:
- sub r1, r1, r3, lsl #2
- subs r0, $1
- bne Lloop
- Ldone:
- mov r0, r3
- Lexit:
- pop {r4-r7}
- bx lr
- Lerror:
- eors r0, r0
- b Lexit
- int f(int v){return v<2?1:v*f(v-1);}
- (Condition) ? (Return this if true) : (Return this if false)
- if (v<2)
- {
- return 1;
- }
- else
- {
- return v*f(v-1);
- }
- f=lambda n:n<2and 1or n*f(n-1)
- sub f($n){[*]1..$n}
- sub f{[*]1..$^n}
- sub postfix:<!>($n){[*]1..$n}
- {[*]1..$^n}
- say {[*]1..$^n}(5) # 120
- def f i;i<2?1:i*f(i-1);end
- ,{1+}%{*}*
- def f(n):return n and n*f(n-1)or 1
- int f(int n){return n?n*f(n-1):1;}
- sub f{$_[0]?$_[0]*f($_[0]-1):1;}
- dc -e'?d[1-dsa*lad1<b]dsbxszp' <<<1000
- dc -e'?[q]sQ[d1=Qd1-lFx*]dsFxp' <<<1000
- int f(int n){return n>1?f(n-1)*n:1;}
- let f n = [1..n] |> Seq.fold ( * ) 1
- seq $n|paste -sd*|bc
- def f(n:Int)=(1/:(1 to n))(_*_)
- f=lambda x:+(x<2)or x*f(x-1)
- fact=:!
- fact=:*/@:(1+i.)
- fact = foldr1 (*) . n -> [1..n]
- If[#<=#2,#,#0[#,2#2]#0[#-#2,2#2]]&[#,1]&
- If[#<1,1,#1#0[#-1]]&[#,0]&
- Times@@Range@#&
- Func<int,int>f=null;f=v=>v<2?1:v*f(v-1);
- def f(n):return (1 if n<2 else n*f(n-1))
- fun f 0=1|f n=n*f(n-1)
- let rec f n = if n=0 then 1 else n*f(n-1);;
- def f(n): return reduce(lambda x,y: x*y,range(1,n+1))
- F(n){return n>1?n*F(n-1):1;}
- decimal f(int v) { return v > 1 ? v * f(v - 1) : 1; }
Add Comment
Please, Sign In to add comment