fact.js with slush_poppies
1 var fact = function(n) {
2 if(n==0) {
3 return 1;
4 } else {
5 return n * arguments.callee(n-1);
6 }
7 }
fact.pl with spacecadet
1 sub fact {
2 my($n) = @_;
3
4 if ($n == 0) {
5 return 1;
6 } else {
7 return $n * fact($n - 1);
8 }
9 }
10
11 printf "%d! = %d\n", 10,fact(10);
12
fact.py with amy
1 def fact(n):
2 if n == 0:
3 return 1L
4 else:
5 return n * fact(n - 1)
6
7 print "%d! = %s" % (10, fact(10))
fact.rb with brilliance_dull
1 def fact(n)
2 if n == 0
3 1
4 else
5 n * fact(n - 1)
6 end
7 end
8
9 printf "%d! = %d\n", 10, fact(10)
fv.rb
1 #!/opt/local/bin/ruby -Ku
2 #
3 # FV = PV(1+r)^n
4 #
5
6 class FCalc
7 def fv(pv,r,n)
8 pv*(1+r)**n
9 end
10 def pv(fv,r,n)
11 fv/(1+r)**n
12 end
13 end
14
15 f = FCalc.new
16 p fv = f.fv(100,0.1,10)
17
18 11.times { |n| p "year #{n}: #{f.fv(100,0.1,n)}" }
No comments:
Post a Comment